x, y = map(int, raw_input().split())
n = map(int, raw_input().split())
d = map(int, raw_input().split())
m1 = min(n)
m2 = min(d)

end = False
for i in range(1, 10):
    if(i in n and i in d):
        output = i
        end = True
        break
    
if(m1 == m2):
    print m1

elif(end):
    print output

elif(m1 < m2):
    if(m1 in d):
        print(m1)
    else:
        print (str(m1) + str(m2))
else:
    if(m2 in n):
        print(m2)
    else:
        print(str(m2) + str(m1))