import java.util.*;

// http://codeforces.com/problemset/problem/870/A
public class PrettyIntegers {
	public static Scanner sc = new Scanner(System.in);
//	2 3
//	4 2
//	5 7 6
	public static void main(String[] args) {
		int[] shit = ria();
		int[] one = ria();
		int[] two = ria();
		Arrays.sort(one);
		Arrays.sort(two);
		if(one[0] == two[0]) {
			print(one[0]);
			return;			
		} else {
			if(one[0] > two[0])
				print(""+two[0] + one[0]);
			else
				print(""+one[0] + two[0]);
		}
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	public static int ri() {
		return Integer.parseInt(sc.nextLine());
	}

	public static long rl() {
		return Long.parseLong(sc.nextLine());
	}

	public static double rd() {
		return Double.parseDouble(sc.nextLine());
	}

	public static String[] rsa() {
		return sc.nextLine().split(" ");
	}

	public static int[] ria() {
		String[] s = rsa();
		int[] arr = new int[s.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Integer.parseInt(s[i]);
		return arr;
	}

	public static long[] rla() {
		String[] s = rsa();
		long[] arr = new long[s.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Long.parseLong(s[i]);
		return arr;
	}

	public static int[] riaml(int m) {
		int[] arr = new int[m];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Integer.parseInt(sc.nextLine());
		return arr;
	}

	public static long[] rlaml(int m) {
		long[] arr = new long[m];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Long.parseLong(sc.nextLine());
		return arr;
	}
}
