n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

d = []
for i in a:
    for k in b:
        x = str(i)
        y = str(k)
        if x == y:
            d.append(int(i))
        else:
            
            num = ''
            num += str(x) + str(y)
            mun = ''
            mun += str(y) + str(x)

            num = int(num)
            mun = int(mun)
            d.append(num)
            d.append(mun)
print(min(d))
