l = list(input().split())
l2 = list(input().split())
l3 = list(input().split())
ot = min(l2[0], l3[0]) + max(l2[0], l3[0])
out = 0

l2.sort()
l3.sort()

for i in l2:
    if out == 1:
        break
    for i2 in l3:
        if i == i2:
            ot = i
            out = 1
            break

print(ot)