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);
if(y[0]==z[0])
	System.out.println(y[0]);
else {
	if(search(y[0],z))
		System.out.println(y[0]);
	else {
		if(search(z[0],y))	
			System.out.println(z[0]);
		else {
			if(y[0]<z[0])
				System.out.println(y[0]+""+z[0]);
			else
				System.out.println(z[0]+""+y[0]);
		}
	}
	}
	}
}
