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[] a = new long[n]; for(int i = 0; i < n; i++) { a[i] = sc.nextLong(); } Arrays.sort(a); long ans = a[n - 1] - a[0]; long[] b = new long[n - 1]; for(int i = 1; i < n; i++) { b[i - 1] = a[i] - a[i - 1]; } Arrays.sort(b); if(n == k) { ans = 0; } else { for(int i = n - 2; i >= n - k; i--) { ans -= b[i]; } } System.out.println(ans); } }