n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if len(set(a)&set(b)) != 0:
    print(min(set(a)&set(b)))
else:
    print(str(min(min(a), min(b))) + str(max(min(a), min(b))))
