#include <stdio.h>

int main() {
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) 
    { 
        int arr1[1000] = {0};
        int arr2[1000] = {0};
        int MergedArr[2000] = {0};
        for (int i = 0; i < a; i++)
        {
            scanf("%d",arr1+i);
        }

        for (int j = 0; j < b;j++)
        {
            scanf("%d",arr2+j);
        }

        int i = 0;
        int j = 0;
        int k = 0;
        while (i < a && j < b)
        {
            if (arr1[i] < arr2[j])
            {
                MergedArr[k] = arr1[i];
                i++;
            }
            else if (arr1[i] > arr2[j])
            {
                MergedArr[k] = arr2[j];
                j++;
            }
            else 
            {
                if (i > j)
                {
                    MergedArr[k] = arr2[j];
                    j++;
                }
                else 
                {
                    MergedArr[k] = arr1[i];
                    i++;
                }
            }
            k++;
        }

        if(i < a)
        {
            for (;i < a;i++,k++)
            {
                MergedArr[k] = arr1[i];
            }
        }

        if (j < b)
        {
            for (;j < b;j++,k++)
            {
                MergedArr[k] = arr2[j];
            }
        }
        
        
        
        for (int k = 0; k < (a+b); k++)
        {
            printf("%d ",MergedArr[k]);
        }

    }
    return 0;
}