#include <iostream>
using namespace std;
int main()
{
    int n , m , min;
    cin >> n >> m;
    int arr1[n] , arr2[m] , arr3[n + m];

    for ( int i = 0 ; i < n ; i ++ )
    {
        cin >> arr1[i];
    }

    for ( int i = 0 ; i < m ; i ++ )
    {
        cin >> arr2[i];
    }
    
    for ( int i = 0 ; i < n ; i ++ )
    {
        for ( int j = 0 ; j < n ; j ++ )
        {
            if ( arr1[i] > arr1[j] && i < j )
            {
                swap ( arr1[i] , arr1[j] );
            }
        }
    }

    for ( int i = 0 ; i < m ; i ++ )
    {
        for ( int j = 0 ; j < m ; j ++ )
        {
            if ( arr2[i] > arr2[j] && i < j )
            {
                swap ( arr2[i] , arr2[j] );
            }
        }
    }

    min = arr1[0];
    int i = 0;
    int andx1 , andx2;
    andx1 = 0;
    andx2 = 0;
    while ( i < (n + m) )
    {
        if ( min > arr2[andx2] )
        {
            arr3[i] = arr2[andx2];
            andx2 ++;
            min = arr2[andx2];

            if ( andx2 > m - 1 && andx1 < n - 1 )
            {
                andx1 ++;
                min = arr1[andx1];
            }
        }

        else if ( min > arr1[andx1] )
        {
            arr3[i] = arr1[andx1];
            andx1 ++;
            min = arr1[andx1];

            if ( andx1 > n - 1 && andx2 < m - 1 )
            {
                andx2 ++;
                min = arr2[andx2];
            }
        }

        else 
        {
            arr3[i] = min;
            if ( min == arr1[andx1] )
            {
                andx1 ++;
                min = arr1[andx1];
            }

            else 
            {
                andx2 ++;
                min = arr2[andx2];
            }
        }

        i ++;
    }


    for ( int i = 0 ; i < n + m ; i ++ )
    {
        cout << arr3[i] <<" ";
    }


    return 0;
}