import java.util.*;
public class Compose {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int j=0;
        int t1[]=new int[n];
        int t2[]=new int[m];
        int tmp[]=new int[9];
        for(int i=0;i<n;i++){
            t1[i]=sc.nextInt();
            ++tmp[t1[i]-1];
        }
        for(int i=0;i<m;i++){
            t2[i]=sc.nextInt();
            ++tmp[t2[i]-1];
        }
        for(j=0;j<9;j++)
        {
            if(tmp[j]>=2)
                break;
        }
        if(j<9){
            System.out.println(j+1);
        }else{
            Arrays.sort(t1);
            Arrays.sort(t2);
            if(t1[0]<t2[0]) {
                System.out.println(t1[0]*10+t2[0]);
            }
            else
                System.out.println(t2[0]*10+t1[0]);
        }
    }
}