n, m = [int(i) for i in input().split()]
a = set([int(i) for i in input().split()])
b = set([int(i) for i in input().split()])
c = a & b
if len(c) == 0:
    n1 = min(a)
    n2 = min(b)
    print(10 * min(n1, n2) + max(n1, n2))
else:
    print(min(c))