
#include <stdio.h>
#include <stdlib.h>

int main() {
    int *A, *B;
    int i = 0, j = 0;
    int x, y;

    // Alokasi memori
    A = (int *)malloc(2000 * sizeof(int));
    B = (int *)malloc(2000 * sizeof(int));

    // Input array A sampai -9
    while (1) {
        scanf("%d", &x);

        if (x == -9)
            break;

        A[i++] = x;
    }

    // Input array B sampai -9
    while (1) {
        scanf("%d", &y);

        if (y == -9)
            break;

        B[j++] = y;
    }

    // Merge dua array terurut
    int p = 0, q = 0;

    while (p < i && q < j) {
        if (A[p] < B[q]) {
            printf("%d ", A[p]);
            p++;
        } else {
            printf("%d ", B[q]);
            q++;
        }
    }

    // Sisa elemen A
    while (p < i) {
        printf("%d ", A[p]);
        p++;
    }

    // Sisa elemen B
    while (q < j) {
        printf("%d ", B[q]);
        q++;
    }

    // Free memory
    free(A);
    free(B);

    return 0;
}

