import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int K = scan.nextInt(); long[]a = new long[N]; for(int i = 0; i < N; i++) { a[i] = scan.nextLong(); } scan.close(); Arrays.sort(a); long[]d = new long[N - 1]; for(int i = 0; i < N - 1; i++) { d[i] = a[i + 1] - a[i]; } Arrays.sort(d); long ans = 0; for(int i = 0; i < N - K; i++) { ans += d[i]; } System.out.println(ans); } }