import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n=Integer.parseInt(br.readLine());
int k=Integer.parseInt(br.readLine());
st=new StringTokenizer(br.readLine());
int[] sensors=new int[n];
for(int i=0;i<n;i++)sensors[i]=Integer.parseInt(st.nextToken());
Arrays.sort(sensors);
int[] distances=new int[n-1];
for(int i=0;i<n-1;i++)distances[i]=sensors[i+1]-sensors[i];
Arrays.sort(distances);
int sum=0;
for(int i=0;i<n-k;i++)sum+=distances[i];
System.out.println(sum);
}
}
#그리디