

import java.util.Scanner;

/**
 * You are given two lists of non-zero digits.
 * 
 * Let's call an integer pretty if its (base 10) representation has at least one
 * digit from the first list and at least one digit from the second list. What
 * is the smallest positive pretty integer?
 */
public class PrettyIntegers {

	/**
	 * Test cases:
	 * 
	 * 2 3 4 2 5 7 6 -> 25
	 * 
	 * 8 8 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 -> 1
	 * 
	 * 1 1 2 1 -> 12
	 */
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			int nSize = s.nextInt();
			int mSize = s.nextInt();
			boolean[] n = new boolean[9];
			boolean[] m = new boolean[9];
			for (int i = 0; i < nSize; i++) {
				n[s.nextInt() - 1] = true;
			}
			for (int i = 0; i < mSize; i++) {
				m[s.nextInt() - 1] = true;
			}
			for (int i = 1; i <= 99; i++) {
				int firstDigit = i / 10;
				int secondDigit = i % 10;
				if (firstDigit == 0) {
					firstDigit = secondDigit;
				}
				if (secondDigit != 0
						&& ((n[firstDigit - 1] && m[secondDigit - 1]) || (n[secondDigit - 1] && m[firstDigit - 1]))) {
					System.out.println(i);
					break;
				}
			}
		}
	}

}
