import java.util.Arrays;
import java.util.Scanner;

public class problems {
    public  static  void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int arr1[] = new int[n];
        int arr2[] = new int[m];
        int min1 = 100, min2 = 100;
        for(int i = 0; i < n; i++) {
            arr1[i] = in.nextInt();
            if(arr1[i] < min1)
                min1 = arr1[i];
        }
        int c = 100;
        for(int i = 0; i < m; i++) {
            arr2[i] = in.nextInt();
            if (arr2[i] < min2)
            min2 = arr2[i];
        }
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                if(arr2[i]==arr1[j])
                    c = Math.min(c, arr2[i]);
            }

        }
        int a = min1*10 + min2;
        int b = min2*10 + min1;
        System.out.print(Math.min(c, Math.min(b, a)));
    }
}
