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)

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