m , n = map(int , input().split())
r = lambda : list(map(int, input().split()))

a = set(r())

b = set(r())




x = a.intersection(b)

if x:
    print(next(iter(x)))

else:
    print(min(a),end="")
    print(min(b))