N,M=map(int,input().split()) A=list(map(int,input().split())) A.sort() D=[0]+[(b-a)**2 for a,b in zip(A,A[1:])] for i in range(1,N): D[i]+=D[i-1] ans=min(D[i+M-1]-D[i] for i in range(N-M+1)) print(ans)