l1 = input()
l2 = set(input().split())
l3 = set(input().split())
l2  = [int(x) for x in l2]
l3 = [int(x) for x in l3]
if min(l2)==min(l3):
    print(min(l2))
else:
    print(str(min(min(l2),min(l3)))+str(max(min(l2),min(l3))))