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

m = 1000000000

for i in a:
    for k in b:
        if i == k and int(i) < m:
            m = int(i)
        elif min(int(i + k), int(k + i)) < m:
            m = min(int(i + k), int(k + i))
print(m)
