input()
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
ma = min(a)
mb = min(b)
num = min(ma, mb)*10 + max(ma, mb)

superNum = 1000
for i in a:
    if i in b and i < superNum:
        superNum = i
if superNum != 1000:
    num = superNum
print(num)