n, m = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))
n = min(a)
m = min(b)
if len(a.intersection(b)) > 0:
    print(min(a.intersection(b)))
else:
    if n > m:
        print(str(m) + str(n))
    else:
        print(str(n) + str(m))
