input()
a = set(map(int, input().split()))
b = set(map(int, input().split()))
x = a.intersection(b)
if x != set():
    print(sorted(x)[0])
else:
    print(str(min(sorted(a)[0],sorted(b)[0])) + str(max(sorted(a)[0],sorted(b)[0])))
