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

	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];
		for (int i = 0; i < n; i++) {
		    arr1[i] = kbd.nextInt();
		}
		int oneDigit1 = -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) {
		        oneDigit1 = i;
		        break;
		    }
		}
        int oneDigit = oneDigit1;
        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]);

            }
        }
	}
}