def element_in_common(a, b):
    i = a.intersection(b)
    if i:
        return min(i)
    else:
        return 0

_ = input()
l1 = set((map(int, input().split())))
l2 = set((map(int, input().split())))

x = min(l1)
y = min(l2)
e = element_in_common(l1, l2)

if e:
    print(e)
else:
    print(min(x, y), max(x, y), sep='')
