import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int p = sc.nextInt();
			int c = sc.nextInt();
			int a[] = new int[p];
			int b[] = new int[c];
			for(int i = 0;i < p;i ++){
				a[i] = sc.nextInt();
			}
			for(int i = 0;i < c;i ++){
				b[i] = sc.nextInt();
			}
			Arrays.sort(a);
			Arrays.sort(b);
			int ans = 10000000;
			for(int i = 0;i < p;i ++){
				for(int j = 0;j < c;j ++){
					if(a[i] == b[j]){ans = Math.min(ans,a[i]);  }
					ans = Math.min(ans,Math.min(a[i],b[j]) * 10 + Math.max(a[i],b[j]));
				}
			}
			System.out.println(ans);
		}
	}
}