import java.util.*;

public class Design_Pattern {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(),m = scan.nextInt();
        int ar1[] = new int [n];
        int ar2[] = new int [m];
        boolean flag = false;
        int value = 10;
        for(int i=0;i<n;i++)
            ar1[i]=scan.nextInt();
        
        Arrays.sort(ar1);
        for(int i=0;i<m;i++){
            ar2[i]=scan.nextInt();
            if(Arrays.binarySearch(ar1,ar2[i]) > -1){
                flag = true;
                value = Math.min(ar2[i],value);
            }
        }
        
       Arrays.sort(ar2);
      if(flag){
          System.out.println(value);
      }
      else{
          int v1 = ar1[0]*10+ar2[0];
          int v2 = ar2[0]*10+ar1[0];
          System.out.println(Math.min(v1, v2));
      }
        
        
    }
}
