import java.util.Scanner;

public class A {
	
	private static Scanner input= new Scanner(System.in);
	
	public static void main(String[] args) {
		int n = input.nextInt();
		int m = input.nextInt();
		int a[] = new int[n];
		int b[] = new int[m];
		int minA = 100, minB = 100, minCommon = 100;
		boolean haveCommon = false;
		boolean aDigits[] = new boolean[10];
		
		for (int i = 0; i < n; i++) {
			a[i] = input.nextInt();
			aDigits[a[i]] = true;
			minA = Math.min(a[i], minA);
		}
		
		for (int i = 0; i < m; i++) {
			b[i] = input.nextInt();
			if (aDigits[b[i]] == true) {
				haveCommon = true;
				minCommon = Math.min(minCommon, b[i]);
			}
			minB = Math.min(b[i], minB);
		}
		
		if (haveCommon)
			System.out.println(minCommon);
		else
			System.out.println(Math.min(minA, minB) + "" + Math.max(minA, minB));
	}
}
