import java.util.Arrays;
import java.util.Scanner;
public class TechnocubA {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        boolean bol=false;
     int []a=new int[n];
     int []b=new int[m];
   int c=0;
      for(int i=0;i<n;i++){
          a[i]=scanner.nextInt();
      }
        for(int i=0;i<m;i++){
            b[i]=scanner.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        int min=a[0];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               if(a[i]==b[j]){
                bol=true;
                if (a[i]<min){
                   min=a[i];
                }
               }
            }
        }
        if(bol==false){
            if(a[0]<b[0]){
              c=a[0]*10+b[0];
            }
            else{
                c=b[0]*10+a[0];
            }
            System.out.print(c);
        } else{
            System.out.print(min);
        }

    }
}
