import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{	
	public static void main (String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int arr1[]=new int[n];
		int arr2[]=new int[m];
		int arr3[]=new int[Math.max(n,m)];
		for(int i=0;i<n;i++){
			arr1[i]=sc.nextInt();
		}
		for(int i=0;i<m;i++){
			arr2[i]=sc.nextInt();
		}
		Arrays.sort(arr1);
		Arrays.sort(arr2);
		int l=0,val=0;
		for(int i=0;i<arr1.length;i++){
            for(int j=0;j<arr2.length;j++){
                if(arr1[i]==arr2[j]){
                	//System.out.println(arr1[j]);
                    arr3[l]=arr1[i];
                    l++;
                }
            }
        }
        int count=0,f=0;
        if(l>0){
        Arrays.sort(arr3);
       
        for(f=0;f<arr3.length;f++){
       	if(arr3[f]!=0){break;}
        if(arr3[f]==0){count++;}
        
    }
    //System.out.println(count);
        System.out.println(arr3[count]);
}
		
		else{
			int x=arr1[0],y=arr2[0];
			System.out.println(Math.min(x,y)+""+Math.max(x,y));
		}
		

		
	}

}
