import java.util.*;
public class cola {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n,n1;
		n=in.nextInt();
		n1=in.nextInt();
		int arr[];
		int arr1[];
		arr=new int[n];
		arr1=new int[n1];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
		}
		for(int i=0;i<n1;i++)
		{
			arr1[i]=in.nextInt();
		}
		Arrays.sort(arr);
		Arrays.sort(arr1);
	   int max=arr[0];
	   int min=arr1[0];
	   int result[];
	   result=new int[n+n1];
	   System.arraycopy(arr, 0, result, 0, n);
	   System.arraycopy(arr1, 0, result, n, n1);
	   Arrays.sort(result);
	   int mid=0;
	   while(mid<=result.length-2)
	   {
		   if(result[mid]==result[mid+1])
		   {
			   System.out.println(result[mid]);
			   System.exit(0);
		   }
		   mid++;
	   }
	   if(min<=max)
	   {
	   System.out.println(min+""+max);
	   }
	   else if(min>=max)
	   {
	   System.out.println(max+""+min);
	   }
	}
}
	