import java.util.Scanner;
import java.util.Arrays;
public class PrettyIntegers {

	public static void main(String[] args) {
		Scanner kbd = new Scanner(System.in);
        int n = kbd.nextInt();
        int m = kbd.nextInt();
        int[] arr1 = new int[n];
        int[] arr2 = new int[m];
        int oneDigit = operations(kbd, n, m, arr1, arr2);
        if (oneDigit > 0) {
            System.out.println(oneDigit);
        } else {
            if (arr1[0] > arr2[0]) {
                System.out.println(arr2[0] + "" + arr1[0]);
            } else {
                System.out.println(arr1[0] + "" + arr2[0]);

            }
        }
	}

	public static int operations(Scanner kbd, int n, int m, int[] arr1, int[] arr2) {
		for (int i = 0; i < n; i++) {
            arr1[i] = kbd.nextInt();
        }
        int oneDigit = -1;
        for (int i = 0; i < m; i++) {
            arr2[i] = kbd.nextInt();
        }
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        for (int i : arr1) {
            if (Arrays.binarySearch(arr2, i) >= 0) {
                oneDigit = i;
                break;
            }
        }
		return oneDigit;
	}
}
