import java.util.Scanner;


public class taskA {

   static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n, m;

        n = sc.nextInt();
        m = sc.nextInt();

        int[] a = enter(n);
        int[] b = enter(m);


        int c = count(a, b);
        if (c != 0) {
            int smaller = 10;
            int[] same = new int[c];
            int h = c--;

            for (int j = 0; j < a.length; j++) {
                for (int k = 0; k < b.length; k++) {
                    if (a[j] == b[k]) {
                        h--;
                        same[h]=a[j];
                    }
                }
            }
            for (int d = 0; d<same.length;d++){
                if (same[d]<smaller){
                    smaller=same[d];
                }
            }
            System.out.println(smaller);

        } else {
            int min1, min2;

            min1 = a[0];
            min2 = b[0];
            for (int i = 0; i < a.length; i++) {
                if (a[i] < min1) {
                    min1 = a[i];
                }
            }
            for (int i = 0; i < b.length; i++) {
                if (b[i] < min2) {
                    min2 = b[i];
                }
            }
            if (min1 > min2) {
                System.out.println(min2 + "" + min1);
            } else if (min1 == min2) {
                System.out.println(min1);
            } else if (min2 > min1) {
                System.out.println(min1 + "" + min2);
            }
        }

    }

    public static int count(int arrayA[], int arrayB[]) {
        int k = 0;
        for (int j = 0;j<arrayA.length;j++){
            for (int i = 0;i<arrayB.length;i++){
                if(arrayA[j]==arrayB[i]){
                    k++;
                }
            }
        }
        return k;

    }
    public static int [] enter (int number){
            int [] array = new int[number];
        for (int i = 0; i < number; i++) {
            array[i] = sc.nextInt();
        }
        return array;
    }
}