
input()

n = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]

mn = min(n)
mm = min(m)

if mn == mm:
    print(mn)
elif mn > mm:
    print('{}{}'.format(mm, mn))
else:
    print('{}{}'.format(mn, mm))
