n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() x=0 for i in range(1,m): x+=(a[i]-a[i-1])**2 res=x for i in range(m,n): x+=(a[i]-a[i-1])**2 x-=(a[i-m+1]-a[i-m])**2 res=min(res,x) print(res)