input()
a = set([int(i) for i in input().split()])
b = set([int(i) for i in input().split()])
c = a & b
if len(c) > 0:
    print(min(c));
else:
    a = min(a)
    b = min(b)
    print(min(a,b) * 10 + max(a,b))
