#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300010;
int con = 0;
int n, m, num[MAXN];
int c[MAXN];
bool cmp(int x, int y) { return x > y; }
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
  }
  for (register int i = 2; i <= n; i++) {
    c[i - 1] = num[i] - num[i - 1];
  }
  sort(c + 1, c + n, cmp);
  int res = num[n] - num[1];
  for (register int i = 1; i <= m - 1; i++) res = res - c[i];
  printf("%d", res);
}
