import java.util.*;
public class beautiful {
	public static void main (String []args) {
		Scanner a=new Scanner(System.in);
		Scanner b=new Scanner(System.in);
		int[]x=new int [2];
		x[0]=a.nextInt();
		x[1]=a.nextInt();
		int []y=new int[x[0]]; //number of treasures
		int []z=new int[x[1]]; //number of keys
		int r=0;
		for(int i=0;i<x[0];i++) {
			y[i]=a.nextInt();
		}
		for(int j=0;j<x[1];j++) {
			z[j]=a.nextInt();
		}
		Arrays.sort(z);
		Arrays.sort(y);
if(y[0]==z[0])
	System.out.println(y[0]);
else {
	if(y[0]<z[0])
		System.out.println(y[0]+""+z[0]);
	else
		System.out.println(z[0]+""+y[0]);
}
	}
}