n, m = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))
c = min(a)
d = min(b)
e = a & b
if len(e) != 0:
    print(min(e))
else:
    print(str(min(c, d)) + str(max(c, d)))
