import java.util.Scanner;
public class P870A
{
	public static void main(String[] args)
	{
	 Scanner scan=new Scanner(System.in);
	 int n,m,i,j=1,k,r;
	 int[] a=new int[9];
	 int[] b=new int[9];
	 boolean flag,flag1;
	 n=scan.nextInt();
	 m=scan.nextInt();
	 for(i=0;i<n;++i)
		a[i]=scan.nextInt();
	 for(i=0;i<m;++i)
		b[i]=scan.nextInt();
	 while(true)
		{
	 	 flag=flag1=false;
		 k=j;
	 	 while(k>0)
			{
			 r=k%10;
			 k/=10;
			 for(i=0;i<n;++i)
				if(r==a[i])
					{
					 flag=true;
					 break;
					}
			 for(i=0;i<m;++i)
				if(r==b[i])
					{
					 flag1=true;
					 break;
					}
			 if(flag&&flag1)
				break;
			}
		 if(flag&&flag1)
			break;
		 ++j;
		}
	 System.out.println(j);
	}
}