import java.util.Scanner;
public class JavaApplication17 {  
   public static int d;
    public static void main(String[] args) {
        Scanner input =new Scanner(System.in);
        int x=input.nextInt();
        int y=input.nextInt();
        int[] first=new int[x];
        int[] Second=new int[y];
        for (int i = 0; i < first.length; i++) {
            first[i]=input.nextInt();
        }
        for (int i = 0; i < Second.length; i++) {
            Second[i]=input.nextInt();
        }
        int firstdigit=1000000000;
        int seconddigit=1000000000;
        for (int j = 0; j < first.length; j++) {
            if(first[j]<firstdigit)
                firstdigit=first[j];
        }
        for (int j = 0; j < Second.length; j++) {
            if(Second[j]<seconddigit)
                seconddigit=Second[j];
        }
        if(firstdigit>seconddigit)
            System.out.print(Integer.parseInt(seconddigit + "" + firstdigit));
        else if(firstdigit<seconddigit)
                System.out.print(Integer.parseInt(firstdigit + "" + seconddigit));
        else
            System.out.print(firstdigit);
    }    
}
				      	    	  	 		 			 				