l = raw_input().strip().split(' ')
n, m = int(l[0]), int(l[1])

l = raw_input().strip().split(' ')
a = [l[i] for i in range(n)]

l = raw_input().strip().split(' ')
b = [l[i] for i in range(m)]

r = 0
for i in range(1, 100):
    x = str(i)
    t1 = sum([1 if j in x else 0 for j in a])
    t2 = sum([1 if j in x else 0 for j in b])

    if t1 > 0 and t2 > 0:
        r = i
        break

print r