import java.util.Scanner;
public class PrettyIntegers {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int minA = 9;
		int minB = 9;
		for(int i = 0; i < a; i++){
			int next = s.nextInt();
			minA = next < minA ? next : minA;
		}
		for(int i = 0; i < b; i++){
			int next = s.nextInt();
			minB = next < minB ? next : minB;
		}
		if(minA == minB) System.out.println(minA);
		else if(minA > minB){
			int prod = minB * 10 + minA;
			System.out.println(prod);
		}else{
			int prod = minA * 10 + minB;
			System.out.println(prod);
		}
	}
}
