input()
a = set(map(int, input().split()))
b = set(map(int, input().split()))

if a.intersection(b) != set():
    print(min(a.intersection(b)))
else:
    print(min([min(a), min(b)]), max([min(a), min(b)]), sep="")
