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