import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); } Arrays.sort(arr); long[] dif = new long[n - 1]; for (int i = 0; i < n - 1; i++) { dif[i] = arr[i + 1] - arr[i]; } Arrays.sort(dif); long ans = 0; for (int i = 0; i < n - k; i++) { ans += dif[i]; } System.out.println(ans); } }