input()
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
x = -1
for i in range(1, 10):
    if i in a and i in b:
        x = i
        break
if a[0] == b[0]:
    print(a[0])
elif x != -1:
    print(x)
else:
    print(min(a[0], b[0]), end="")
    print(max(a[0], b[0]))