import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int size1=sc.nextInt();
        int size2=sc.nextInt();
        int[] arr1=new int[size1];
        int[] arr2=new int[size2];
        for(int i=0;i<size1;i++)arr1[i]=sc.nextInt();
        for(int i=0;i<size2;i++)arr2[i]=sc.nextInt();
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        boolean flag2=false;
        for(int i=0;i<size1;i++){
            boolean flag=false;
            for(int j=0;j<size2;j++){
                if(arr1[i]==arr2[j]){
                    System.out.println(arr1[i]);
                    flag=true;
                    break;
                }
            }
            if(flag){flag2=true;break;}
        }
        if(!flag2){
        if(arr1[0]<arr2[0]) System.out.println(arr1[0]+""+arr2[0]);
        
        else if(arr1[0]>arr2[0]) System.out.println(arr2[0]+""+arr1[0]);}
    }
}