//https://codeforces.com/problemset/problem/870/A

import java.util.Scanner;

public class P870A {

    private static int getPretty(int[] a, int[] b) {
        int[] hasha = new int[10];
        int[] hashb = new int[10];
        for (int i: a) hasha[i]++;
        for (int i: b) hashb[i]++;
        int smallesta = 10, smallestb = 10;
        for (int i = 1; i <= 9; i++) {
            if(hasha[i] > 0)
                smallesta = Math.min(i, smallesta);
            if (hashb[i] > 0)
                smallestb = Math.min(i, smallestb);
        }
        return smallesta == smallestb ? smallesta : smallesta*10 + smallestb;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for (int i = 0; i < n; i++)
            a[i] = sc.nextInt();
        for (int i = 0; i < m; i++)
            b[i] = sc.nextInt();
        System.out.println(getPretty(a, b));
    }
}
