

import java.util.Scanner;

public class TaskA {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		byte n = in.nextByte();
		byte m = in.nextByte();

		byte min1 = 10, min2 = 10;

		for (int i = 0; i < n; i++) {
			byte a = in.nextByte();
			if (a < min1)
				min1 = a;
		}

		for (int i = 0; i < m; i++) {
			byte a = in.nextByte();
			if (a < min2)
				min2 = a;
		}

		if (min1 == min2) {
			System.out.print(min1);
		} else if (min1 > min2) {
			System.out.print(Byte.toString(min2) + Byte.toString(min1));
		} else
			System.out.print(Byte.toString(min1) + Byte.toString(min2));

	}

}
