


import java.util.Scanner;


public class water2 {
	public static Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		while(cin.hasNext()) {
			int n=cin.nextInt();
			int m=cin.nextInt();
			int[] arrn=new int[10];
			int[] arrm=new int[10];
			for(int i=0;i<n;i++) {
				arrn[cin.nextInt()]++;
			}
			for(int i=0;i<m;i++) {
				arrm[cin.nextInt()]++;
			}
			int minn=10;
			int minm=10;
			int res=0;
			for(int i=0;i<10;i++) {
				if(arrm[i]==1&&arrn[i]==1) {
					res=i;
					break;
				}else if(arrn[i]==1&&i<minn){
					minn=i;
				}else if(arrm[i]==1&&i<minm){
					minm=i;
				}
			}
			if(res!=0) {
				System.out.println(res);
			}else {
				System.out.println(minm<minn?minm*10+minn:minn*10+minm);
			}
		}
	}
}
