import java.util.*;
public class A870 {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num1 = scan.nextInt(), num2 = scan.nextInt(), min1 = 9, min2 = 9, digit = 0, rep = 100;
		boolean[] array = new boolean[10];
		for(int i = 0; i < num1; i++){
			digit = scan.nextInt();
			array[digit] = true;
			if(min1 > digit)
				min1 = digit;
		}
		for(int i = 0; i < num2; i++){
			digit = scan.nextInt();
			if(array[digit]){
				if(rep > digit)
				rep = digit;
			}
			if(min2 > digit)
				min2 = digit;
		}
		digit = Math.min(min1, min2) * 10 + Math.max(min1, min2);
		if(rep < digit)
			System.out.println(rep);
		else
			System.out.println(digit);
	}
}