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 = 9, min2 = 9;
        for(int i = 0; i < n; i++) {
            arr1[i] = in.nextInt();
            if (arr1[i] < min1)
                min1 = arr1[i];
        }
        for(int i = 0; i < m; i++) {
            arr2[i] = in.nextInt();
            if (arr2[i] < min2)
                min2 = arr2[i];
        }
        if(min1==min2)
            System.out.print(min1);
        else if(min1<min2)
            System.out.print(min1 + "" + min2);
        else
            System.out.print(min2 + "" + min1);
    }
}
