n, m = [int(i) for i in input().split()]
s1 = set([int(i) for i in input().split()])
s2 = set([int(i) for i in input().split()])
a1 = min(s1)
a2 = min(s2)

i = s1.intersection(s2)

try:
    print(min(i))
except:
    print(str(min(a1, a2))+str(max(a1, a2)))