n = list(map(int, input().rstrip().split()))
L1 = list(map(int, input().rstrip().split()))
L2 = list(map(int, input().rstrip().split()))

intersection = list(set(L1) & set(L2))


if(len(intersection) != 0):
    print(min(intersection))
else:
    min1 = min(L1)
    min2 = min(L2)
    if(min1 > min2):
        print(str(min2) + str(min1))
    else:
        print(str(min1) + str(min2))