import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int x[] = new int[a];
		int y[] = new int[b];
		int minA = 9;
		int minB = 9;

		for (int i = 0; i < a; i++) {
			x[i] = s.nextInt();
		}
		for (int i = 0; i < b; i++) {
			y[i] = s.nextInt();
		}

		for (int i = 0; i < a; i++) {
			if (x[i] < minA) {
				minA = x[i];
			}
		}

		for (int i = 0; i < b; i++) {
			if (y[i] < minB) {
				minB = y[i];
			}
		}

		if (minA == minB) {
			System.out.println(1);
		} else if (minA == 1 && minB == 9) {
			System.out.print(minB);
		} else if (minA > minB) {
			System.out.println(minB+""+minA);
		} else if (minB > minA) {
			System.out.println(minA+""+minB);
		}
	}// class
}// main