import java.util.Scanner; 
public class FinalsProgram {
public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int lengthOfList1 = kbd.nextInt();
        int lengthOfList2=  kbd.nextInt();
        boolean[] listOne = new boolean[9];
        boolean[] listTwo = new boolean[9];
        
        for (int num=0; num<lengthOfList1; num++) {
            listOne[kbd.nextInt()-1] = true;        
        }
        
        for (int num = 0; num < lengthOfList2; num++) {
            listTwo[kbd.nextInt()-1] = true;
        }
        
        for (int finalAns=1;finalAns<=99;finalAns++) {
            int numOne = finalAns / 10;
            int numTwo = finalAns % 10;
            
            if (numOne==0) {
                numOne=numTwo;
            }
            boolean checkDetails = (numTwo!=0) && ((listOne[numOne-1] && listTwo[numTwo-1]) || (listOne[numTwo - 1] && listTwo[numOne - 1]));
            
            if (checkDetails) {
                System.out.println(finalAns);
                break;
            }
        }
    }   
}