n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = list(set(a) & set(b))
if c:
    print(min(c))
else:
    a = min(a)
    b = min(b)
    print(str(min(a, b)) + str(max(a, b)))
