input()
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))

a = min(s1)
b = min(s2)

r = set(s1).intersection(set(s2))
if len(r) > 0:
    print(min(r))
else:
    print(str(min(a, b))+str(max(a, b)))