import java.util.Scanner;

public class Driver {

	public static Scanner scanner;
	public static void main(String[] args) {
		scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int b1[] = new int[10];
		int b2[] = new int[10];
		
		int m1 = Integer.MAX_VALUE;
		int m2 = m1;
		for(int i=0; i<n; i++) {
			int a = scanner.nextInt();
			b1[a]++;
			m1 = Math.min(m1, a);
		}
		for(int i=0; i<m; i++) {
			int a = scanner.nextInt();
			b2[a]++;
			m2 = Math.min(m2, a);
		}
		
		for(int i=0; i<10; i++)
			if(b1[i]!=0 && b2[i]!=0) {
				System.out.println(i);
				return;
			}
		
		System.out.println(Math.min(m1, m2) + "" + Math.max(m1, m2));
		
		
	}

}




















