# 

lens = input().split()
l1 = input().split()
l2 = input().split()

min1, min2 = min(l1), min(l2)
result = ''
intersects = set(l1) & set(l2)

if len(intersects) != 0:
    result = min(intersects)
elif min1 == min2 or min1 in l2:
    result = min1
elif min2 in l1:
    result = min2
else:
    result = min([min1, min2]) + max([min1, min2]) 

print(result)