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,max,tmp;
        min = read(sc);
        for(int i=1;i<n;i++){
            tmp = read(sc);
            if(min>tmp)
                min = tmp;
        }
        max = read(sc);
        for(int i = 1;i<m;i++){
            tmp = read(sc);
            if(tmp<max)
                max = tmp;
        }
        if(max==min)
            System.out.println(min);
        else if(min>max)
            System.out.println(max+""+min);
        else
            System.out.println(min+""+max);
    }
}