import java.util.*;
public class Main {
    public static boolean contains(int[] arr, int x) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == x) {
                return true;
            }
        }
        return false;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = in.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        boolean flag = false;
        for (int i = 1; i <= 9; i++) {
            if (contains(a, i) && contains(b, i)) {
                System.out.println(i);
                flag = true;
                break;
            }
        }
        if (!flag) {
            int A = a[0];
            int B = b[0];
            System.out.println(Math.min(A, B) + "" + Math.max(A, B));
        }
    }
}