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

if c:
    print(min(c))
else:
    print(sorted((min(a), min(b))), sep='')
