import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,K,*A = map(int,read().split()) A.sort() DA = [y-x for x,y in zip(A,A[1:])] DA.sort() answer = sum(DA[:N-K]) print(answer)