import java.util.Scanner;

public class TechCup {
    public static void main(String [] Args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int min1 = 999999999;
        int min2 = 999999999;
        int mineq = 999999999;
        int [] li1 = new int [n];
        int [] li2 = new int [m];
        for (int i=0;i<n;i++) li1[i] = in.nextInt();
        for (int i=0;i<m;i++) {
            li2[i] = in.nextInt();
            for (int k=0;k<n;k++){
                if (li2[i]==li1[k] && li2[i]<mineq) mineq = li2[i];
            }
        }
        for (int i=0;i<n;i++) {
            if (li1[i]< min1) min1=li1[i];
        }

        for (int i=0;i<m;i++) {
            if (li2[i]< min2) min2=li2[i];
        }
        int res = 0;
        if (min1 != min2) res = Math.min(min1,min2)*10 + Math.max(min1,min2);
        else res = min1;
        System.out.print(Math.min(res,mineq));
    }
}