n, m = [int(i) for i in input().split()]
a1 = str(min([int(i) for i in input().split()]))
a2 = str(min([int(i) for i in input().split()]))

if (a1 in a2):
    print(a2)
elif (a2 in a1):
    print(a1)
else:
    print(str(min(int(a1), int(a2)))+str(max(int(a1), int(a2))))