def main1(n,k,a): if k==1:return max(a)-min(a) a.sort() ary=[] for i,(x,y) in enumerate(zip(a,a[1:])): ary.append(y-x) ary.sort() return max(a)-min(a)-sum(ary[-k+1:]) if __name__=='__main__': n,k=map(int,input().split()) a=list(map(int,input().split())) #ret0=main0(n,k,a) ret1=main1(n,k,a) #print(ret0) print(ret1)