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:
    x = min(a.union(b))
    if x in a:
        print(x, min(b), sep='')
    else:
        print(x, min(a), sep='')
