a, b = tuple(map(int, input().split()))
list1 = list(map(int, input().split()))
list2= list(map(int, input().split()))
minimum = 100
 
for num1 in list1:
    for num2 in list2:
        if num1 == num2:
            if num1 < minimum:
                minimum = num1
        else:
            result = num1*10 + num2
            if result < minimum:
                minimum = result
 
print(minimum)