import java.util.Scanner;
import java.util.Arrays;
public class PrettyNumbers{
	public static void main(String args[]){
		Scanner kbd = new Scanner(System.in);
		int n = kbd.nextInt();
		int m = kbd.nextInt();
		int[] firstList = new int[10];
		int[] secondList = new int[10];
		for(int i = 0; i < n; i++) {
			firstList[i] = kbd.nextInt();
		}
		for(int i = 0; i < m; i++) {
			secondList[i] = kbd.nextInt();
		}
		int result = 0;
		int min = 100;
		
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				if (firstList[i] == secondList[j] && firstList[i] < min){
					min = firstList[i];
				}
				if (firstList[i] > secondList[j] && (secondList[j] * 10 + firstList[i]) < min){
					min = (secondList[j] * 10 + firstList[i]);
				}
				if (firstList[i] < secondList[j] && (firstList[i] * 10 + secondList[j]) < min){
					min = (firstList[i] * 10 + secondList[j]);
				}
			}
		}
		System.out.println(min);
	}
	
}