import java.util.Scanner;

/**
 * Created by omka on 11/2/17.
 */
public class A {

    public static void main(String[] args){

        Scanner in  = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();
        int[] ab=new int[11];
        int[] ac=new int[11];
        int ab1=9;
        int ac1=9;
        for (int i = 0; i < n; i++) {
            int tmp = in.nextInt();
            ab[tmp]=1;
            ab1 = Math.min(ab1, tmp);
        }

        for (int i = 0; i < m; i++) {
            int tmp = in.nextInt();
            ac[tmp]=1;
            ac1 = Math.min(ac1, tmp);
        }

        int ans=0;
        for (int i = 1; i < 10; i++) {
              if(ab[i]==1 && ac[i]==1){
                  ans=i;
                  System.out.println(ans);
                  System.exit(0);
              }
        }

        if(ab1>ac1){
            System.out.println(ac1+""+ab1);
        }
        else{
            System.out.println(ab1+""+ac1);
        }

    }

}
