import java.util.Scanner;

public class Main {
    public static int min(int a,int b){
        return a>b?b:a;
    }
    public static int max(int a,int b){
        return a<b?b:a;
    }
    public static void main(String args[]){
        Scanner in=new Scanner(System.in);
        int lenFirst=in.nextInt();
        int lenSecond=in.nextInt();
        int first[]=new int[lenFirst];
        int second[]=new int[lenSecond];
        for(int i=0;i<lenFirst;i++)
            first[i]=in.nextInt();
        for(int i=0;i<lenSecond;i++)
            second[i]=in.nextInt();
        int min=100;
        for(int i=0;i<lenFirst;i++)
            for(int g=0;g<lenSecond;g++)
                min=min(min,first[i]==second[g]?first[i]:min(first[i]*10+second[g],second[g]*10+first[i]));
        System.out.print(min);
    }
}
