import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Q870A {
	
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] sizes = in.readLine().split(" ");
		int[] l1 = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int[] l2 = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		System.out.println(solution(l1, l2));
	}

	private static String solution(int[] l1, int[] l2) {
		int min = Arrays.stream(l1).min().getAsInt();
		int min2 = Arrays.stream(l2).min().getAsInt();
		if (min != min2) {
			if (min < min2) {
				return min + "" + min2;
			}else{
				return min2 + "" + min;
			}
		}else{
			return min + "";
		}
	}
}