m, n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
min1 = min(a)
min2 = min(b)
if min1 > min2:
    print(min2 * 10 + min1)
elif min2 > min1:
    print(min1 * 10 + min2)
else:
    print(min1)
