s = input().split(' ')
n = int(s[0])
m = int(s[1])

p1 = [ int(i) for i in input().split(' ')]
p2 = [ int(i) for i in input().split(' ')]
min1, min2 = min(p1), min(p2)

if p1 == p2:
    print(p1)
elif p1 > p2:
    print(min2*10+min1)
else:
    print(min1*10+min2)
