def nonZero(a, b):
    if min(a) == min(b):
        return min(a)

    return min(min(a) * 10 + min(b), min(b) * 10 + min(a))


nm = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
print(nonZero(a, b))
