import java.util.*;



public class scorify {
	 
	   
	 
	  
	  public static void main(String[] args) {
		
	 Scanner sc=new Scanner(System.in);
	 int len1=sc.nextInt();
	 int len2=sc.nextInt();
	 int [] digit1=new int[len1];
	 int[] digit2=new int[len2];
	 for(int i=0;i<len1;++i) digit1[i]=sc.nextInt();
	 for(int i=0;i<len2;++i) digit2[i]=sc.nextInt();
	 Arrays.sort(digit1);
	 Arrays.sort(digit2);
	 int min1=digit1[0];
	 int min2=digit2[0];
	 if(min1==min2) System.out.print(min1);
	 else System.out.println(Math.min(min1,min2)+""+Math.max(min1,min2));
			  
}
	
}