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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		ArrayList<Integer> list1 = new ArrayList<>(n);
		ArrayList<Integer> list2 = new ArrayList<>(m);
		for (int i = 0; i < n; i++) {
			list1.add(in.nextInt());

		}
		for (int j = 0; j < m; j++) {
			list2.add(in.nextInt());
		}
		int aa = 100500;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (list1.get(i) == list2.get(j))
					aa = Math.min(aa, list1.get(i));
				else {
					aa = Math.min(aa, list1.get(i) * 10 + list2.get(j));
					aa = Math.min(aa, list2.get(j) * 10 + list1.get(i));

				}
			}

		}
		System.out.println(aa);
	}

}
