def nonZero(a, b):
    a.sort()
    for i in a:
        if b.count(i) > 0:
            return i

    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))
