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

x = min(a)
y = min(b)

num = ''
num += str(x) + str(y)
mun = ''
mun += str(y) + str(x)

if x == y:
    print(x)
else:
    num = int(num)
    mun = int(mun)
    if num <= mun:
        print(num)
    else:
        print(mun)
