import java.util.*;
public class My {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(),m = scan.nextInt(),b=10,a=10,w[] = new int[10];
        for(int i=0;i<n;i++){
            int k = scan.nextInt();
            a=Math.min(a,k);
            w[k]++;
        }
        for(int i=0;i<m;i++){
            int k= scan.nextInt();
            b=Math.min(b,k);
            w[k]++;
        }
        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));
    }
}