import sys input=lambda: sys.stdin.readline().rstrip() n,m=map(int,input().split()) D=sorted([int(input()) for _ in range(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(abs(D[n-1+i]),abs(D[i]))) print(ans)