import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class PrettyInteger {
    private static int read(Scanner sc){
        int b;
        do{
            b = sc.nextInt();
        }while(b<1 || b>10);
        return b;
    }
    public static void main(String args[]){
        Scanner sc= new Scanner(System.in);
        int n=read(sc),m=read(sc);
        int min,min2,tmp;
        int ar[] = new int[n];
        int ar2[] = new int[m];
        min = read(sc);
        ar[0]=min;
        for(int i=1;i<n;i++){
            tmp = read(sc);
            ar[i]=tmp;
            if(min>tmp)
                min = tmp;
        }
        min2 = read(sc);
        ar2[0]=min2;
        for(int i = 1;i<m;i++){
            tmp = read(sc);
            ar2[i]=tmp;
            if(tmp<min2)
                min2 = tmp;
        }
        Arrays.sort(ar);
        Arrays.sort(ar2);
        int x=0;
        if(m>n){
            for(int i:ar){
                if(Arrays.binarySearch(ar2,i)>-1){
                    x=i;
                    break;
                }
            }
        }else{
            for(int i:ar2){
                if(Arrays.binarySearch(ar,i)>-1){
                    x=i;
                    break;
                }
            }
        }
        if(x>0)
            System.out.println(x);
        else if(min>min2)
            System.out.println(min2+""+min);
        else
            System.out.println(min+""+min2);
    }
}