n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = min(a)
b = min(b)
if a == b:
    print(a)
else:
    print(str(min(a, b)) + str(max(a, b)))
