n ,m = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
kek = set(a)
lol = set(b)
g = lol & kek
if len(g):
    print(min(g))
    exit(0)
n1 = min(a)
n2 = min(b)
s = ""
s += str(min(n1, n2))
s += str(max(n1,n2 ))
print(s)