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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer> mas1 = new ArrayList<>();
        ArrayList<Integer> mas2 = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            mas1.add(sc.nextInt());
        }
        for (int i = 0; i < m; i++) {
            mas2.add(sc.nextInt());
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (mas1.get(i) == mas2.get(j) && mas1.get(i) < min)
                    min = mas1.get(i);
                else if (Integer.parseInt("" + mas1.get(i) + mas2.get(j)) < min)
                    min = Integer.parseInt("" + mas1.get(i) + mas2.get(j));
                else if (Integer.parseInt("" + mas2.get(j) + mas1.get(i)) < min)
                    min = Integer.parseInt("" + mas2.get(j) + mas1.get(i));

            }
        }
        System.out.println(min);

    }
}
