import java.util.Scanner;

public class TaskA {
    public static void main(String[] args) {
        Scanner  scan = new Scanner(System.in);
        int[] list1,list2;
        String s = scan.nextLine();
        list1 = new int[Integer.valueOf(""+s.charAt(0))];
        list2 = new int[Integer.valueOf(""+s.charAt(2))];
        s = scan.nextLine().replaceAll(" ","");
        for (int i = 0; i<s.length();i++)
            list1[i]=Integer.valueOf(""+s.charAt(i));
        s = scan.nextLine().replaceAll(" ","");
        for (int i = 0; i<s.length();i++)
            list2[i]=Integer.valueOf(""+s.charAt(i));
        sort(list1);
        sort(list2);
        boolean a,b;
        for (int i = 1; i<100;i++) {
            a=false;
            b=false;
            s=""+i+0;
            for (int i1 = 0;i1<list1.length;i1++)
                if ((Integer.valueOf(""+s.charAt(0))==list1[i1]) ||(Integer.valueOf(""+s.charAt(1))==list1[i1])) a=true;
            for (int i1 = 0;i1<list2.length;i1++)
                if ((Integer.valueOf(""+s.charAt(0))==list2[i1]) ||(Integer.valueOf(""+s.charAt(1))==list2[i1])) b=true;
            if (a&&b) {
                System.out.println(i);
                break;
            }
        }
    }
    static void sort(int[] arr) {
        for (int i = arr.length - 1; i > 0; i--) {
            for (int c = 0; c < i; c++) {
                if (arr[c] > arr[c + 1]) {
                    int t = arr[c];
                    arr[c] = arr[c + 1];
                    arr[c + 1] = t;
                }
            }
        }
    }
}
