import java.util.Scanner;

public class A870 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();
        boolean[] first = new boolean[10];
        boolean[] second = new boolean[10];
        for (int n=0; n<N; n++) {
            first[in.nextInt()] = true;
        }
        for (int m=0; m<M; m++) {
            second[in.nextInt()] = true;
        }
        int answer = 1;
        while (true) {
            if (found(answer, first) && found(answer, second)) {
                break;
            }
            answer++;
        }
        System.out.println(answer);
    }

    private static boolean found(int number, boolean[] set) {
        while (number != 0) {
            int digit = number%10;
            number /= 10;
            if (set[digit]) {
                return true;
            }
        }
        return false;
    }

}
