n, m = map(int, input().split())

s1 = set(input().split())
s2 = set(input().split())

a = min(s1)
b = min(s2)
c = s1.intersection(s2)

if c:
    print(min(c))
elif a < b:
    print(str(a) + str(b))
else:
    print(str(b) + str(a))
