(n, m) = map(int, input().split())

a = []
for x in input().split():
    a.append(int(x))
b = []
for x in input().split():
    b.append(int(x))

lst = []
for x in a:
    for y in b:
        if x == y:
            lst.append(x)
        else:
            lst.append(int(str(x) + str(y)))
            lst.append(int(str(y) + str(x)))
print(min(lst))
        
'''
a1 = min(a)
b1 = min(b)

if a1 == b1:
    print(a1)
elif a1 > b1:
    print(b1, a1, sep = '')
else:
    print(a1, b1, sep = '')
'''
