n1, n2 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s1 = min(a)
s2 = min(b)
if s1 > s2:
    s = str(s2) + str(s1)
elif s1 < s2:
    s = str(s1) + str(s2)
else:
    s = str(s1)
for i in range(10):
    if i in a and i in b:
        s = i
        break
print(s)