import sys input=lambda: sys.stdin.readline().rstrip() n,m=map(int,input().split()) D=sorted([int(input()) for _ in ragnge(m)]) ans=0 for i in range(m-n+1): if D[i]<=0<=D[n-1+i]: ans=min(ans,D[n-1+i]-D[i]) else: ans=min(ans,max(D[n-1+i],D[i])) print(ans)