#include <stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define OVERFLOW -2
typedef int Status;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct
{
int *elem;
int length;
int listsize;
}Sqlist;
Status InitList_Sq(Sqlist &L)
{
L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem) return OVERFLOW;
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
Status ListInsert_Sq(Sqlist &L,int i,int e)
{
int *newbase;
int *p,*q;
if(i<1||i>L.length+1) return ERROR;
if(L.length>=L.listsize)
{
newbase=(int*)malloc((L.listsize+LISTINCREMENT)*sizeof(int));
if(!newbase) return OVERFLOW;
L.elem=newbase;
L.listsize=L.listsize+LISTINCREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]); p>=q; --p)
{
*(p+1)=*p;
}
*q=e;
L.length++;
return OK;
}
Status MergeList(Sqlist La,Sqlist Lb,Sqlist &Lc,Status(*ListInsert_Sq)(Sqlist &Lc,int i,int e))
{
int i,j,k;
int La_len,Lb_len;
//InitList_Sq(Lc);
i=j=0;k=1;
La_len=La.length;
Lb_len=Lb.length;
while(i<La_len||j<Lb_len)
{
if(La.elem[i]<=Lb.elem[j])
{
ListInsert_Sq(Lc,k++,La.elem[i]);
i++;
}
else
{
ListInsert_Sq(Lc,k++,Lb.elem[j]);
j++;
}
}
while (i<La_len)
{
ListInsert_Sq(Lc,k++,La.elem[i]);
i++;
}
while (j<Lb_len)
{
ListInsert_Sq(Lc,k++,Lb.elem[j]);
j++;
}
return OK;
}
int main()
{
Sqlist La,Lb,Lc;
int i,j,e;
int m,n;
InitList_Sq(La);
InitList_Sq(Lb);
InitList_Sq(Lc);
while (scanf("%d%d",&m,&n)&&(m>0)&&(n>0))
{
La.length=m;
Lb.length=n;
Lc.length=La.length+Lb.length;
for(i=1;i<=m;i++)
{
scanf("%d",&e);
ListInsert_Sq(La,i,e);
//printf("%d\n",La.elem[i]);
}
for(i=1;i<=n;i++)
{
scanf("%d",&e);
ListInsert_Sq(Lb,i,e);
}
/*for (j=0;j<m;j++)
{
printf("%d ",La.elem[j]);
}
printf("\n");
for (j=0;j<n;j++)
{
printf("%d ",Lb.elem[j]);
}
printf("\n");*/
MergeList(La,Lb,Lc,ListInsert_Sq);
for (j=0;j<7;j++)
{
printf("%d ",Lc.elem[j]);
}
printf("\n");
}
return OK;
}