import java.util.Scanner;

public class p870a {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int minA = 10;
        int[] freq = new int[10];
        for (int i = 0; i < n; ++i) {
            int val = scanner.nextInt();
            ++freq[val];
            minA = Math.min(minA, val);
        }

        int minB = 10;
        for (int i = 0; i < m; ++i) {
            int val = scanner.nextInt();
            ++freq[val];
            minB = Math.min(minB, val);
        }

        int res = -1;
        for (int i = 0; i < freq.length; ++i) {
            if (freq[i] > 1) {
                res = i;
                break;
            }
        }

        if (res == -1) {
            res = Math.min(minA, minB) * 10 + Math.max(minA, minB);
        }

        scanner.close();

        System.out.println(res);
    }
}
