import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int ans = 0;
			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 t = -1;
			if(a[0] == b[0]){t = a[0];}
			if(t != -1){ans = Math.min(a[0] * 10 + b[0],t);}
			else{ans = a[0] * 10 + b[0];}
			System.out.println(ans);
		}
	}
}
	  		    	 						  	 			 				