import java.util.Arrays;
import java.util.Scanner;

public class A870_Pretty_Numbers {

	public static void main(String[] args) {
		
		Scanner input = new Scanner(System.in);
		
		int first = input.nextInt();
		int second = input.nextInt();
		int[] firstarr = new int[first];
		int[] secondarr = new int[second];
		for (int i = 0; i < first; i ++) {
			firstarr[i] = input.nextInt();
		}

		for (int i = 0; i < second; i ++) {
			secondarr[i] = input.nextInt();
		}
		
		Arrays.sort(firstarr);
		Arrays.sort(secondarr);
		if (secondarr[0] == firstarr[0]) {
			System.out.println(secondarr[0]);
		}
		else if (secondarr[0] * 10 + firstarr[0] < firstarr[0] * 10 + secondarr[0]) {
			System.out.println(secondarr[0] * 10 + firstarr[0]);
		}
		else {
			System.out.println(firstarr[0] * 10 + secondarr[0]);
		}
	}

}
