import java.util.*;
public class cola {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n,n1;
		n=in.nextInt();
		n1=in.nextInt();
		int arr[];
		int arr1[];
		arr=new int[n];
		arr1=new int[n1];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
		}
		for(int i=0;i<n1;i++)
		{
			arr1[i]=in.nextInt();
		}
	    Arrays.sort(arr);
	    Arrays.sort(arr1);
	    if(arr[0]==arr1[0])
	    {
	    	System.out.println(arr[0]);
	    }
	    else
	    {
	    	if(arr[0]>arr1[0])
	    	{
	    		System.out.println(arr1[0]+""+arr[0]);
	    	}
	    	else if(arr[0]<arr1[0])
	    	{
	    		System.out.println(arr[0]+""+arr1[0]);
	    	}
	    	else
	    	{
	    		System.out.println(arr[0]+""+arr1[0]);
	    	}
	    }
	}
}


	    	