# task 1
input()

A = set(map(int, input().split()))
B = set(map(int, input().split()))

mi = min(A|B)
print(mi, end='')

if mi in A&B:
    print()
elif mi in A:
    print(min(B))
else:
    print(min(A))