N,K=map(int,input().split()) a=list(map(int,input().split())) a.sort() b=[] for i in range(N-1): b.append((a[i+1]-a[i],i)) b.sort(reverse=True) c=[b[i][1] for i in range(K-1)] c=set(c) ans=0 check=set() for i in range(N): check.add(a[i]) if i in c or i==N-1: ans+=max(check)-min(check) check=set() print(ans)