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 minA = 100, minB = 100;
		for (int i = 0; i < n; i++)
			minA = Math.min(minA, input.nextInt());
		for (int i = 0; i < m; i++)
			minB = Math.min(minB, input.nextInt());
		
		System.out.print(Math.min(minA, minB) + "" + Math.max(minA, minB));
	}

}
