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