n, m = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))

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