
input()

n = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]

same = []

for i in n:
    if i in m:
        same.append(i)

mn = min(n)
mm = min(m)

if mn == mm:
    ret = mn
elif mn > mm:
    ret = int('{}{}'.format(mm, mn))
else:
    ret = int('{}{}'.format(mn, mm))

for i in same:
    if i < ret:
        ret = i
        break

print(ret)
