q = input().split()
l1 = input().split()
l2= input().split()
l1.sort()
l2.sort()
nM = 0

if int(l1[0]) < int(l2[0]):
    nM = int(str(l1[0])+str(l2[0]))
else:
    nM = int(str(l2[0]) + str(l1[0]))

for i in l1:
    if i in l2:
        if int(i) < int(nM):
            nM = i
print(nM)