import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int arr1[] = new int[n];
        int arr2[] = new int[m];
        int min1 = 10;
        int min2 = 10;
        for (int i = 0; i < n; i++) {
            arr1[i] = scanner.nextInt();
            if (min1 > arr1[i]){
                min1 = arr1[i];
            }
        }
        for (int i = 0; i < m; i++) {
            arr2[i] = scanner.nextInt();
            if (min2 > arr2[i]){
                min2 = arr2[i];
            }
        }
        if (min1 == min2){
            System.out.println(min1);
        }else{
            int number1 = min1*10 + min2;
            int number2 = min2*10 + min2;
            if (number1 < number2){
                System.out.println(number1);
            }else{
                System.out.println(number2);
            }
        }
    }
}