s = input()
l1 = set(map(int, input().split()))
l2 = set(map(int, input().split()))
l3 = l1 & l2
l1_min = min(l1)
l2_min = min(l2)
if len(l3) > 0:
    print(min(l3))
elif l1_min == l2_min:
    print(l1_min)
elif l1_min < l2_min:
    print('{}{}'.format(l1_min, l2_min))
else:
    print('{}{}'.format(l2_min, l1_min))
