import java.util.*;

public class Task1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size1, size2, min1, min2, result = 0;
        int[] arr1, arr2;
        size1 = sc.nextInt();
        size2 = sc.nextInt();
        arr1 = new int[size1];
        arr2 = new int[size2];

        for (int i = 0; i < size1; i++)
            arr1[i] = sc.nextInt();
        for (int i = 0; i < size2; i++)
            arr2[i] = sc.nextInt();
        min1 = arr1[0];
        min2 = arr2[0];
        for (int i = 0; i < size1; i++)
            if (arr1[i] < min1)
                min1 = arr1[i];
        for (int i = 0; i < size2; i++)
            if (arr2[i] < min2)
                min2 = arr2[i];
        if (min1 == min2)
            result = min1;
        else if (min1 > min2)
            result = min2 * 10 + min1;
        else
            result = min1 * 10 + min2;
        System.out.println(result);
    }
}
