n, m = list(map(int, input().split()))
a = set(map(int, input().split()))
b = set(map(int, input().split()))
min_a = min(a)
min_b = min(b)
minn = min_b*10+min_a if (min_a*10+min_b > min_b*10+min_a) else min_a*10+min_b
ob = a.intersection(b)
d = 100000
if bool(ob):
    d = int(min(ob))
print(d if d < minn else minn)