import java.util.Arrays; import java.util.Scanner; public class No615 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); if(N == K) { System.out.println(0); }else { long a[] = new long[N]; for(int i = 0;i < N;i++) { a[i] = sc.nextLong(); } Arrays.sort(a); if(K == 1) { System.out.println(a[N-1] - a[0]); }else { int b[] = new int[K-1]; //分割する位置を入れる配列(a[i] a[i+1]の間で分割するならiが入る) long max[] = new long[K-1]; long sum = 0; for(int i = 0;i < K-1;i++) { max[i] = 0; } for(int i = 0;i < N-1;i++) { if(max[0] < a[i+1] - a[i]) { max[0] = a[i+1] - a[i]; b[0] = i; Arrays.sort(max); Arrays.sort(b); } } for(int i = 0;i < K-1;i++) { if(i == 0) { sum += a[b[i]] - a[0]; }else { sum += a[b[i]] - a[b[i-1]+1]; } if(i + 1 == K - 1) { sum += a[N-1] - a[b[i]+1]; } } System.out.println(sum); } } } }