import java.util.*;
public class MyClass {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x[] = new int[n];
        int m = scan.nextInt();
        int y[] = new int[m];
        int w[] = new int[10];
        int b=10,a=10;
        for(int i=0;i<n;i++){
            x[i] = scan.nextInt();
            a=Math.min(a,x[i]);
            w[x[i]]++;
        }
        for(int i=0;i<m;i++){
            y[i] = scan.nextInt();
            b=Math.min(b,y[i]);
            w[y[i]]++;
        }
        for(int i=1;i<10;i++)if(w[i]==2){System.out.print(i);System.exit(0);}
        System.out.print(Math.min(a,b)+""+Math.max(a,b));
    }
}
