#include <bits/stdc++.h>
using namespace std;
long long s1[100010];
long long cir[100010];
int main() {
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long sum = 0;
  n--;
  for (int i = 1; i <= n; i++) {
    cin >> s1[i];
    sum += s1[i];
  }
  if (m >= n) {
    cout << sum << endl;
    return 0;
  } else {
    memset(cir, 0, sizeof(cir));
    long long l = 1, r = 1;
    for (int i = 1; i <= n; i++) {
      if (i <= m) {
        cir[r] = s1[i];
        r++;
      } else {
        while (l < r) {
          if (cir[l] <= s1[i]) {
            cir[r] += cir[l];
            s1[i] -= cir[l];
            cir[l] = 0;
          } else {
            cir[l] -= s1[i];
            cir[r] += s1[i];
            s1[i] = 0;
          }
          while (cir[l] == 0 || r - l + 1 > m) l++;
          if (s1[i] <= 0) break;
        }
        r++;
      }
    }
    long long finasum = 0;
    for (int i = l; i <= r; i++) {
      finasum += cir[i];
    }
    cout << finasum << endl;
  }
  return 0;
}
