n, m = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))
if len(a & b):
    print(sorted(list(a & b))[0])
else:
    print(str(min(min(a), min(b))) + str(max(min(a), min(b))))
