import java.util.Scanner;

public class PrettySearch {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		boolean[] set1 = new boolean[9];
		boolean[] set2 = new boolean[9];
		int n = scan.nextInt();
		int m = scan.nextInt();
		for(int i = 0; i < n; i++){
			set1[scan.nextInt()-1] = true;
		}
		for(int i = 0; i < m; i++){
			set2[scan.nextInt()-1] = true;
		}
		int min1 = 10;
		int min2 = 10;
		for(int i = 0; i < 9; i++){
			if(set1[i] && set2[i]){
				System.out.println(i+1);
				return;
			}
			if(set1[i] && min1 == 10){
				min1 = i+1;
			}
			if(set2[i] && min2 == 10){
				min2 = i+1;
			}
		}
		int min = Math.min(min1, min2);
		int max = Math.max(min1, min2);
		System.out.println(min+""+max);
	}
}
