import java.util.ArrayList;
import java.util.Scanner;

public class BeautifulNumberSearch {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        ArrayList<Integer> one = new ArrayList<Integer>();
        ArrayList<Integer> two = new ArrayList<Integer>();
        findMinWhileScanning(one, n, scanner);
        findMinWhileScanning(two, m, scanner);
        int answer = 10 * Math.min(one.get(0), two.get(0)) + Math.max(one.get(0), two.get(0));
        for (int i = 1; i <= 9; i++) {
            if (one.contains(i) && two.contains(i)) {
                answer = i;
                break;
            }
        }
        System.out.println(answer);
    }
    static void findMinWhileScanning(ArrayList<Integer> list, int listEnd, Scanner sc) {
        for (int i = 0; i < listEnd; i++) {
            list.add(sc.nextInt());
            if (i > 0) {
                for (int j = i; j > 0; j--) {
                    if (list.get(j) < list.get(j - 1)) {
                        int temp = list.get(j - 1);
                        list.set(j - 1, list.get(j));
                        list.set(j, temp);
                    }
                }
            }
        }
    }
}