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