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