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