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

if len(a & b) > 0:
    print(min(a & b))
else:
    print(min(min(a), min(b)), max(min(a), min(b)), sep="")