n = input()
l1 = [int(i) for i in input().split(' ')]
l2 = [int(i) for i in input().split(' ')]
inter = list(set(l1).intersection(set(l2)))
if len(inter) > 0:
    print(min(inter))
else:
    print(str(min([min(l1),min(l2)])) + str(max([min(l1),min(l2)])))
