n, m = map(int, input().split())
ar = sorted(list(map(int, input().split())))
br = list(map(int, input().split()))
rez = 0
for i in ar:
    if i in br:
        rez = i
        break
if rez:
    print(rez)
else:
    a, b = min(ar), min(br)
    a, b = min(a, b), max(a, b)
    print(a * 10 + b)
