import java.util.*;

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