n, m = [int(x) for x in input().split(' ')]
a = set(int(x) for x in input().split(' '))
b = set(int(x) for x in input().split(' '))

c = a.intersection(b)
if len(c) == 0:
    print(''.join([str(min(min(a), min(b))), str(max(min(a), min(b)))]))
else:
    print(min(c))

