import java.util.*;
public class beautiful {
public static boolean search(int x,int[]y) {
	for(int i=0;i<y.length;i++) {
		if(y[i]==x)
			return true;
	}
return false;
}
	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]]; 
		int []z=new int[x[1]]; 
		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);
		boolean f=true;
if(y[0]==z[0]) {
	System.out.println(y[0]);
	f=false;
}
	for(int g=0;g<y.length&f;g++) {
		if(search(y[g],z)) {
			System.out.println(y[g]);
			f=false;
			break;
		}
			}
		for(int k=0;k<z.length&f;k++)
			if(search(z[k],y))	{
				System.out.println(z[k]);
				f=false;
				break;
			}
	if(y[0]<z[0]&f)
		System.out.println(y[0]+""+z[0]);
	if(y[0]>z[0]&f)
		System.out.println(z[0]+""+y[0]);
	}
}