#include <bits/stdc++.h>
int main() {
  int n, i, j;
  int count = 0;
  int k;
  int sum = 0;
  scanf("%d", &n);
  scanf("%d", &k);
  int buf[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &buf[i]);
  }
  if (k == 1) {
    printf("%d", buf[0]);
    return 0;
  }
  for (j = 0; j < n - 1; j++) {
    if (count == k) break;
    if (buf[j] < buf[j + 1]) {
      sum += buf[j];
      count += 1;
    } else {
      sum += buf[j + 1];
      count += 1;
    }
  }
  printf("%d", sum);
  return 0;
}
