#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

void err(istream_iterator<string> it) {cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[" << *it << " = " << a << "] ";
    err(++it, args...);
}

#define F first
#define S second
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pf push_front
#define db double
#define ld long double
#define ofk order_of_key
#define fbo find_by_order
#define ppb pop_back
#define ppf pop_front
#define br cout << '\n'
#define pll pair<long long, long long>
#define pipii pair<int, pii>
#define ppiii pair<pii, int>
#define piipii pair<pii, pii>
#define here cout << "HERE\n"
#define bruh cout << "BRUH\n"
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int TT; cin >> TT; for(int T = 1; T <= TT; T++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

pair<int, int> dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

const int inf = 2e9 + 7;
const ll INF = 3e18 + 7;
const ld pi = 3.1415926535897932384626433;
const db eps = 1e-6;
const ld EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll MOD = 1e15 + 7;

const bool multiple_tests = 0;
const int N = 3e5 + 7;

#define int long long
#define pii pair<int, int>

int have[N];

void solve() {
    int n, l;
    cin >> n >> l;
    int a[n + 1];
    set<int> st;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        if (a[i]) st.insert(i);
    }
    st.insert(n);
    a[0] = 0;
    have[0] = a[n] = inf;
    for (int i = 0; i < n; i++) {
        while (have[i]) {
            auto it = st.upper_bound(i + l);
            if (it == st.begin()) break;
            it--;
            if (*it <= i) break;
            int tmp = min(a[*it], have[i]);
            have[i] -= tmp;
            a[*it] -= tmp;
            have[*it] += tmp;
            if (!a[*it]) st.erase(*it);
            if (!tmp) break;
        }
    }
    for (int i = 0; i <= n; i++) {
//        error(i, a[i], have[i]);
    }
    cout << have[n];
}

signed main() { __
//  freopen("palindrome.in", "r", stdin);
//  freopen("palindrome.out", "w", stdout);
    int TT = 1;
    if (multiple_tests) cin >> TT;
    for (int testcase = 1; testcase <= TT; testcase++) {
        solve();
        cout << '\n';
    }

//    #ifndef SSYernar
//      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
//    #endif
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

void err(istream_iterator<string> it) {cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[" << *it << " = " << a << "] ";
    err(++it, args...);
}

#define F first
#define S second
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pf push_front
#define db double
#define ld long double
#define ofk order_of_key
#define fbo find_by_order
#define ppb pop_back
#define ppf pop_front
#define br cout << '\n'
#define pll pair<long long, long long>
#define pipii pair<int, pii>
#define ppiii pair<pii, int>
#define piipii pair<pii, pii>
#define here cout << "HERE\n"
#define bruh cout << "BRUH\n"
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int TT; cin >> TT; for(int T = 1; T <= TT; T++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

pair<int, int> dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

const int inf = 2e9 + 7;
const ll INF = 3e18 + 7;
const ld pi = 3.1415926535897932384626433;
const db eps = 1e-6;
const ld EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll MOD = 1e15 + 7;

const bool multiple_tests = 0;
const int N = 3e5 + 7;

#define int long long
#define pii pair<int, int>

int have[N];

void solve() {
    int n, l;
    cin >> n >> l;
    int a[n + 1];
    set<int> st;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        if (a[i]) st.insert(i);
    }
    st.insert(n);
    a[0] = 0;
    have[0] = a[n] = inf;
    for (int i = 0; i < n; i++) {
        while (have[i]) {
            auto it = st.upper_bound(i + l);
            if (it == st.begin()) break;
            it--;
            if (*it <= i) break;
            int tmp = min(a[*it], have[i]);
            have[i] -= tmp;
            a[*it] -= tmp;
            if (!a[*it]) st.erase(*it);
            have[*it] += tmp;
            if (!tmp) break;
        }
    }
    for (int i = 0; i <= n; i++) {
//        error(i, a[i], have[i]);
    }
    cout << have[n];
}

signed main() { __
//  freopen("palindrome.in", "r", stdin);
//  freopen("palindrome.out", "w", stdout);
    int TT = 1;
    if (multiple_tests) cin >> TT;
    for (int testcase = 1; testcase <= TT; testcase++) {
        solve();
        cout << '\n';
    }

//    #ifndef SSYernar
//      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
//    #endif
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

void err(istream_iterator<string> it) {cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[" << *it << " = " << a << "] ";
    err(++it, args...);
}

#define F first
#define S second
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pf push_front
#define db double
#define ld long double
#define ofk order_of_key
#define fbo find_by_order
#define ppb pop_back
#define ppf pop_front
#define br cout << '\n'
#define pll pair<long long, long long>
#define pipii pair<int, pii>
#define ppiii pair<pii, int>
#define piipii pair<pii, pii>
#define here cout << "HERE\n"
#define bruh cout << "BRUH\n"
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int TT; cin >> TT; for(int T = 1; T <= TT; T++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

pair<int, int> dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

const int inf = 2e9 + 7;
const ll INF = 3e18 + 7;
const ld pi = 3.1415926535897932384626433;
const db eps = 1e-6;
const ld EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll MOD = 1e15 + 7;

const bool multiple_tests = 0;
const int N = 3e5 + 7;

#define int long long
#define pii pair<int, int>

int have[N];

void solve() {
    int n, l;
    cin >> n >> l;
    int a[n + 1];
    set<int> st;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        if (a[i]) st.insert(i);
    }
    st.insert(n);
    a[0] = 0;
    have[0] = a[n] = 100;
    for (int i = 0; i < n; i++) {
        while (have[i]) {
            auto it = st.upper_bound(i + l);
            if (it == st.begin()) break;
            it--;
            if (*it <= i) break;
            int tmp = min(a[*it], have[i]);
            have[i] -= tmp;
            a[*it] -= tmp;
            if (!a[*it]) st.erase(*it);
            have[*it] += tmp;
            if (!tmp) break;
        }
    }
    for (int i = 0; i <= n; i++) {
//        error(i, a[i], have[i]);
    }
    cout << have[n];
}

signed main() { __
//  freopen("palindrome.in", "r", stdin);
//  freopen("palindrome.out", "w", stdout);
    int TT = 1;
    if (multiple_tests) cin >> TT;
    for (int testcase = 1; testcase <= TT; testcase++) {
        solve();
        cout << '\n';
    }

//    #ifndef SSYernar
//      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
//    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long int INF = 1e18;

int w, l;
long long int v[MAXN], resp = INF, soma;

int main ()
{
	scanf("%d %d", &w, &l);

	for(int i = 0; i < w - 1; i++)	scanf("%lld", &v[i]);

	for(int i = 0; i < l && i < w - 1; i++)	soma += v[i];

	for(int i = 0; i + l < w; i++)
	{
//		printf("soma (%d - %d) = %lld\n", i, i + l - 1, soma);
		resp = min(resp, soma);
		soma += v[i + l];
		soma -= v[i];
	}

	printf("%lld\n", resp);
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long int INF = 1e18;

int w, l;
long long int v[MAXN], qtd[MAXN];

void see()
{
	printf("\nv   : ");
	for(int i = 1; i < w; i++)	printf("%d ", v[i]);
	printf("\nqtd : ");
	for(int i = 1; i < w; i++)	printf("%d ", qtd[i]);
	printf("\n\n");
}

int main ()
{
	scanf("%d %d", &w, &l);

	for(int i = 1; i < w; i++)	scanf("%d", &v[i]);

	qtd[0] = INF;
	v[w] = INF;
	for(int i = 0; i < w; i++)
	{
		for(int j = i + l; j > i; j--)
		{
			if(qtd[i] >= v[j]) qtd[i] -= v[j], qtd[j] += v[j], v[j] = 0;
			else	v[j] -= qtd[i], qtd[j] += qtd[i], qtd[i] = 0;
			if(qtd[i] == 0)	break;
		}
//		see();
	}

	printf("%lld\n", qtd[w]);
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long int INF = 1e18;

int w, l;
long long int v[MAXN], resp = INF, soma;

int main ()
{
	scanf("%d %d", &w, &l);

	for(int i = 1; i < w; i++)	scanf("%lld", &v[i]);

	for(int i = 1; i < 1 + l; i++)	soma += v[i];

	for(int i = 1; i + l < w; i++)
	{
		soma += v[i + l];
		resp = min(resp, soma);
		soma -= v[i];
	}

	printf("%lld\n", resp);
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long int INF = 1e18;

int w, l;
long long int v[MAXN], resp = INF, soma;

int main ()
{
	scanf("%d %d", &w, &l);

	for(int i = 0; i < w - 1; i++)	scanf("%lld", &v[i]);

	for(int i = 0; i < l; i++)	soma += v[i];

	for(int i = 0; i + l < w; i++)
	{
		soma += v[i + l];
//		printf("soma = %lld\n", soma);
		resp = min(resp, soma);
		soma -= v[i];
	}

	printf("%lld\n", resp);
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long int INF = 1e18;

int w, l;
long long int v[MAXN], resp = INF, soma;

int main ()
{
	scanf("%d %d", &w, &l);

	for(int i = 1; i < w; i++)	scanf("%lld", &v[i]);

	for(int i = 1; i < 1 + l; i++)	soma += v[i];

	for(int i = 1; i + l <= w; i++)
	{
		soma += v[i + l];
//		printf("soma = %lld\n", soma);
		resp = min(resp, soma);
		soma -= v[i];
	}

	printf("%lld\n", resp);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n >> k;
    vl A;
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }

    rep(i, k) { a += A[i]; }
    ans = a;
    rep(i, n - k) {
        a -= A[i];
        a += A[i];
        chmin(ans, a);
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n >> k;
    vl A;
    rep(i, n-1) {
        cin >> x;
        A.push_back(x);
    }

    rep(i, k) { a += A[i]; }
    ans = a;
    rep(i, n - k-1) {
        a -= A[i];
        a += A[i+k];
        chmin(ans, a);
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n >> k;
    vl A;
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }

    rep(i, k) { a += A[i]; }
    ans = a;
    rep(i, n - k) {
        a -= A[i];
        a += A[i+k];
        chmin(ans, a);
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n >> k;
    vl A;
    rep(i, n-1) {
        cin >> x;
        A.push_back(x);
    }

    rep(i, k) { a += A[i]; }
    ans = a;
    rep(i, n - k) {
        a -= A[i];
        a += A[i+k];
        chmin(ans, a);
    }

    cout << ans << endl;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; // find_by_order(), order_of_key()
using ll = long long int;
using i64 = long long int;
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " =: " << a << endl;
    err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& buf) {
    return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v) {
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++) {
        if(!first) os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const set<T>& v) {
    bool first = true;
    os << "{";
    for (auto ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii;
        first = false;
    }
    return os << "}";
}
inline std::ostream &operator << (std::ostream & os,const std::multiset<pair<int,int>,greater<pair<int,int>>>& v) {
    bool first = true;
    os << "{";
    for (auto x: v) {
        if(!first) os << ", ";
        os << x;
        first = false;
    }
    return os << "}";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v) {
    bool first = true;
    os << "{";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii ;
        first = false;
        return os << "}";
    }
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const vector<vector<T>>& v) {
    for (auto &u: v) os << '\n' << u;
    return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
#define PI 3.14159265358979323846
/***********************************************************************/
inline int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}
inline int sub(int a, int b) {
    a -= b;
    if (a < 0) a += MOD;
    return a;
}
inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}
inline int mpow(int base, long long ex, int mod = MOD) {
    int res = 1;
    while (ex > 0) {
        if (ex & 1) res = (long long) res * base % mod;
        base = (long long) base * base % mod;
        ex >>= 1;
    }
    return res;
}
inline int inv(int a, int mod = MOD) {
    return mpow(a, mod - 2, mod);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    vector<int> a(n - 1);
    for (int &e: a) cin >> e;

    int ans = MOD, sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        sum += a[i];
        if (i - m >= 0) {
            sum -= a[i - m];
            uin(ans, sum);
        }
    }
    cout << ans << '\n';

    return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; // find_by_order(), order_of_key()
using ll = long long int;
using i64 = long long int;
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " =: " << a << endl;
    err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& buf) {
    return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v) {
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++) {
        if(!first) os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const set<T>& v) {
    bool first = true;
    os << "{";
    for (auto ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii;
        first = false;
    }
    return os << "}";
}
inline std::ostream &operator << (std::ostream & os,const std::multiset<pair<int,int>,greater<pair<int,int>>>& v) {
    bool first = true;
    os << "{";
    for (auto x: v) {
        if(!first) os << ", ";
        os << x;
        first = false;
    }
    return os << "}";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v) {
    bool first = true;
    os << "{";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii ;
        first = false;
        return os << "}";
    }
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const vector<vector<T>>& v) {
    for (auto &u: v) os << '\n' << u;
    return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
#define PI 3.14159265358979323846
/***********************************************************************/
inline int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}
inline int sub(int a, int b) {
    a -= b;
    if (a < 0) a += MOD;
    return a;
}
inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}
inline int mpow(int base, long long ex, int mod = MOD) {
    int res = 1;
    while (ex > 0) {
        if (ex & 1) res = (long long) res * base % mod;
        base = (long long) base * base % mod;
        ex >>= 1;
    }
    return res;
}
inline int inv(int a, int mod = MOD) {
    return mpow(a, mod - 2, mod);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    vector<int> a(n - 1);
    for (int &e: a) cin >> e;

    int ans = MOD, sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        sum += a[i];
        if (i - m >= 0) {
            sum -= a[i - m];
            uin(ans, sum);
        }
    }
    if (ans == MOD) ans = 0;
    cout << ans << '\n';

    return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; // find_by_order(), order_of_key()
using ll = long long int;
using i64 = long long int;
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
template <typename T> inline void ckmax(T &x, T y) {if (y > x) x = y; }
template <typename T> inline void ckmin(T &x, T y) {if (y < x) x = y; }

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " =: " << a << endl;
    err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& buf) {
    return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v) {
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++) {
        if(!first) os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const set<T>& v) {
    bool first = true;
    os << "{";
    for (auto ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii;
        first = false;
    }
    return os << "}";
}
inline std::ostream &operator << (std::ostream & os,const std::multiset<pair<int,int>,greater<pair<int,int>>>& v) {
    bool first = true;
    os << "{";
    for (auto x: v) {
        if(!first) os << ", ";
        os << x;
        first = false;
    }
    return os << "}";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v) {
    bool first = true;
    os << "{";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii ;
        first = false;
        return os << "}";
    }
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const vector<vector<T>>& v) {
    for (auto &u: v) os << '\n' << u;
    return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
#define PI 3.14159265358979323846
/***********************************************************************/
inline int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}
inline int sub(int a, int b) {
    a -= b;
    if (a < 0) a += MOD;
    return a;
}
inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}
inline int mpow(int base, long long ex, int mod = MOD) {
    int res = 1;
    while (ex > 0) {
        if (ex & 1) res = (long long) res * base % mod;
        base = (long long) base * base % mod;
        ex >>= 1;
    }
    return res;
}
inline int inv(int a, int mod = MOD) {
    return mpow(a, mod - 2, mod);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    vector<int> a(n - 1);
    for (int &e: a) cin >> e;

    auto f = [&] (int x) {
        vector<int> need(n + m, 0), b(a);
        need[n - 1] = x;
        for (int p = n - 1 - m; p >= 0; ) {
            int i = p, j = p + m;
            int it = i + m, jt = j + m;
            while (i < it && j < jt) {
                if (need[j] > b[i]) {
                    need[i] += b[i];
                    need[j] -= b[i];
                    b[i] = 0;
                    ++i;
                } else {
                    need[i] += need[j];
                    b[i] -= need[j];
                    need[j] = 0;
                    ++j;
                }
            }
            if (i == it) return false;
            if (p == 0) return true;
            p = max(0, p - m);
        }
    };
    int lo = 0, hi = 1e9;
    while (lo < hi) {
        int mid = (lo + hi + 1) >> 1;
        if (f(mid)) {
            lo = mid;
        } else {
            hi = mid - 1;
        }
    }
    cout << lo << '\n';

    return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; // find_by_order(), order_of_key()
using ll = long long int;
using i64 = long long int;
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " =: " << a << endl;
    err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& buf) {
    return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v) {
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++) {
        if(!first) os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const set<T>& v) {
    bool first = true;
    os << "{";
    for (auto ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii;
        first = false;
    }
    return os << "}";
}
inline std::ostream &operator << (std::ostream & os,const std::multiset<pair<int,int>,greater<pair<int,int>>>& v) {
    bool first = true;
    os << "{";
    for (auto x: v) {
        if(!first) os << ", ";
        os << x;
        first = false;
    }
    return os << "}";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v) {
    bool first = true;
    os << "{";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii ;
        first = false;
        return os << "}";
    }
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const vector<vector<T>>& v) {
    for (auto &u: v) os << '\n' << u;
    return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
#define PI 3.14159265358979323846
/***********************************************************************/
inline int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}
inline int sub(int a, int b) {
    a -= b;
    if (a < 0) a += MOD;
    return a;
}
inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}
inline int mpow(int base, long long ex, int mod = MOD) {
    int res = 1;
    while (ex > 0) {
        if (ex & 1) res = (long long) res * base % mod;
        base = (long long) base * base % mod;
        ex >>= 1;
    }
    return res;
}
inline int inv(int a, int mod = MOD) {
    return mpow(a, mod - 2, mod);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    vector<int> a(n - 1);
    for (int &e: a) cin >> e;

    int ans = MOD, sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        sum += a[i];
        if (i - m >= 0) {
            sum -= a[i - m];
        }
        if (i + 1 >= m) uin(ans, sum);
    }
    cout << ans << '\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define pb                          push_back

const ll MX5 = 2*1e5+3;
const ll MX6 = 2*1e6+3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD2= 998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}

ll A[MX5],q[MX5],p=0;
ll w,l,sum=0;
bool check(ll m){
    if(m>sum) return 0;
    p=1;
    ll ok=0;
    q[0]=m;
    for(ll i=1;i<=w-1;i++){
        ll need=A[i-1];
        for(ll j=max(i-l,ok);j<=i-1;j++){
            if(need>0){
                if(q[j]>need){
                    q[j]-=need;
                    need=0;
                    ok=j;
                }
                else{
                    need-=q[j];
                    q[j]=0;
                    ok=j+1;
                }
            }
        }
        q[i]=A[i-1]-need;
    }
    ll now=0;
    for(int i=w-l;i<w;i++) now+=q[i];
    if(now==m){
        return 1;
    }
    return 0;
}

int main(){
    fast_io
    //file_io
    cin >> w >> l;
    for(int i=0;i<w-1;i++) cin >> A[i],sum+=A[i];
    ll l=0,r=1e10;
    while(r-l>1){
        ll m=(l+r)/2;
        if(check(m)){
            l=m;
        }
        else{
            r=m;
        }
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define pb                          push_back

const ll MX5 = 5*1e5+3;
const ll MX6 = 2*1e6+3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD2= 998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
vector<ll> v[MX5];
pll A[MX5],B[MX5];
ll n,L[MX5],R[MX5];
void merg_sort(ll l,ll r){
    if(l==r){
        return;
    }
    if(r-l==1){
        if(A[r].F<A[l].F){
            L[A[r].S]++;
            swap(A[r],A[l]);
            R[A[l].S]++;
            L[A[r].S]++;
        }
        return;
    }
    ll m=(r+l)/2;
    merg_sort(l,m);
    merg_sort(m+1,r);
    ll now=l,p1=l,p2=m+1;
    while(now<=r){
        if(p1>m){
            B[now]=A[p2];
            p2++;
        }
        else if(p2>r){
            R[A[p1].S]+=p2-(m+1);
            B[now]=A[p1];
            p1++;
        }
        else{
            if(A[p1].F>A[p2].F){
                B[now]=A[p2];
                L[A[p2].S]+=m-p1+1;
                p2++;
            }
            else{
                R[A[p1].S]+=p2-(m+1);
                B[now]=A[p1];
                p1++;
            }
        }
        now++;
    }
    for(int i=l;i<=r;i++){
        A[i]=B[i];
    }
    return;
}
int main(){
    fast_io
    //file_io
    cin >> n;
    ll nn=2e5+1;
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        v[a+nn].pb(i);
        //A[i]={a,i};
    }

    ll now=1;
    for(int i=0;i<MX5;i++){
        sort(all(v[i]),greater<ll>());
        for(int j=v[i].size()-1;j>=0;j--){
            A[v[i][j]]={now,v[i][j]};
            now++;
        }
    }
    for(int i=0;i<n;i++) cout << A[i].F << sep;
    merg_sort(0,n-1);
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=L[i]*R[i];
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define pb                          push_back

const ll MX5 = 3*1e5+3;
const ll MX6 = 2*1e6+3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD2= 998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}

ll A[MX5];
ll w,l;
bool check(ll m){
    queue<pll> q;
    q.push({m,0});
   // error2("#######3",m);
    for(int i=1;i<=w;i++){
        while(!q.empty() && i-q.front().S>l) q.pop();
        ll need=A[i];
        //error("@");
        //error2(A[i],need);
        while(!q.empty() && need>0){
           // error2(q.front().F,q.front().S);
            if(q.front().F<=need){
                need-=q.front().F;
                q.pop();

            }
            else{
                q.front().F-=need;
                need=0;
            }
        }
        q.push({A[i]-need,i});
    }
    ll sum=0;
    while(!q.empty()){
        sum+=q.front().F;
        q.pop();
    }
    if(sum==m){
        return 1;
    }
    return 0;
}
int main(){
    fast_io
    //file_io
    cin >> w >> l;
    for(int i=1;i<=w-1;i++) cin >> A[i];
    A[w]=INF;
    ll l=0,r=1e10;
    while(r-l>1){
        ll m=(r+l)/2;
        if(check(m)){
            l=m;
        }
        else{
            r=m;
        }
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define pb                          push_back

const ll MX5 = 2*1e5+3;
const ll MX6 = 2*1e6+3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD2= 998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}

ll A[MX5],q[MX5],p=0;
ll w,l,sum=0;
bool check(ll m){
    if(m>sum) return 0;
    p=1;
    q[0]=m;
    for(ll i=1;i<=w-1;i++){
        ll need=A[i-1];
        for(ll j=max(i-l,0ll);j<=i-1;j++){
            if(need>0){
                if(q[j]>need){
                    q[j]-=need;
                    need=0;
                }
                else{
                    need-=q[j];
                    q[j]=0;
                }
            }
        }
        q[i]=A[i-1]-need;
    }
    ll now=0;
    for(int i=w-l;i<w;i++) now+=q[i];
    if(now==m){
        return 1;
    }
    return 0;
}

int main(){
    fast_io
    //file_io
    cin >> w >> l;
    for(int i=0;i<w-1;i++) cin >> A[i],sum+=A[i];
    ll l=0,r=1e10;

    while(r-l>1){
        ll m=(l+r)/2;
        if(check(m)){
            l=m;
        }
        else{
            r=m;
        }
    }
    cout << l;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)	scanf("%d", &a[i]);

	int ans = 0;
	for (int i = 1; i <= l; i++)
	{
		int temp = 1e9;
		for (int j = i; j < w; j += l)
			temp = min(temp, a[j]);
		//cout << i << ' ' << temp << endl;
		ans += temp;
	}
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn], qian[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)
	{
		scanf("%d", &a[i]);
		qian[i] = qian[i - 1] + a[i];
	}

	int ans = 1e9;
	for (int i = l; i < w; i++)
		ans = min(ans, qian[i] - qian[i - l]);
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)	scanf("%d", &a[i]);

	int ans = 1e9;
	for (int i = 0; i + l < w; i += l)
	{
		int temp = 0;
		for (int j = i + 1; j <= min(i + l, w - 1); j++)
			temp += a[j];
		ans = min(ans, temp);
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)	scanf("%d", &a[i]);

	int ans = 1e9;
	for (int i = 0; i + l < w; i += l)
	{
		int temp = 0;
		for (int j = i + 1; j <= min(i + l, w - 1); j++)
			temp += a[j];
		ans = min(ans, temp);
	}

	printf("%d\n", ans);

	return 0;
}
///


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn], qian[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)
	{
		scanf("%d", &a[i]);
		qian[i] = qian[i - 1] + a[i];
	}

	int ans = qian[l];
	for (int i = l + 1; i < w; i++)
		ans = min(ans, qian[i] - qian[i - l - 1]);
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)	scanf("%d", &a[i]);

	int ans = 1e9;
	for (int i = 0; i + l < w; i += l)
	{
		int temp = 0;
		for (int j = 1; j <= l; j++)
			temp += a[i + j];
		ans = min(ans, temp);
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)	scanf("%d", &a[i]);

	int ans = 1e9;
	for (int i = 0; i + l + 1 < w; i += l)
	{
		int temp = 0;
		for (int j = i + 1; j <= min(i + l + 1, w - 1); j++)
			temp += a[j];
		ans = min(ans, temp);
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mn = 1e5 + 10;

int a[mn];
int main()
{
	int w, l;	scanf("%d %d", &w, &l);
	for (int i = 1; i < w; i++)	scanf("%d", &a[i]);

	int ans = 1e9;
	for (int i = 1; i + l - 1 < w; i += l)
	{
		int temp = 0;
		for (int j = i; j < i + l; j++)
			temp += a[j];
		ans = min(ans, temp);
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_W = 1e5;
int a[MAX_W + 1], used[MAX_W + 1], path[MAX_W + 1];
int w, j_s;

int find_path()
{
    //cout << "IN" << endl;
    int path_len = 0, cur_cord = 0, found = INT_MAX;

    while (cur_cord < w)
    {
        if (cur_cord + j_s >= w)
        {
            cur_cord = w;
            break;
        }
        for (int i = cur_cord + j_s; i >= cur_cord; i--)
        {
            if (i == cur_cord)
            {
                return 0;
            }

            if (a[i] - used[i])
            {
                found = min(found, a[i] - used[i]);
                cur_cord = i;
                path[path_len++] = i;
                break;
            }
        }
    }

    if (cur_cord == w)
    {
        for (int i = 0; i < path_len; i++)
        {
            used[path[i]] += found;
        }

        return found;
    }
    //cout << "OUT" << endl;
    return 0;
}

bool can_pass(long long q)
{
    fill(used + 1, used + w + 1, 0);

    while (q)
    {
        int change = min(q, static_cast<long long>(find_path()));
        if (change == 0)
            break;
        q -= change;
    }

    return q == 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> w >> j_s;
    for (int i = 1; i < w; i++)
    {
        cin >> a[i];
    }

    long long l = -1, r = 1e9;
    while (r - l > 1)
    {
        long long m = (l + r) / 2;

        if (can_pass(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }

    cout << l;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_W = 1e5;
int w, l, a[MAX_W + 1];

bool find_next(int& cur, int& cur_left)
{
    if (cur_left)
    {
        cur_left--;
        return true;
    }
    else
    {
        for (int i = cur + 1; i <= w; i++)
        {
            if (a[i])
            {
                cur = i;
                cur_left = a[i] - 1;
                return true;
            }
        }
        return false;
    }
}

bool can(int k)
{
    int cur_i = 0, cur_i_left = 1, cur_i_k = 0, cur_i_k_left = 1;
    for (int i = 0; i < k; i++)
    {
        if (!find_next(cur_i_k, cur_i_k_left))
        {
            return false;
        }
    }

    if (cur_i_k - cur_i > l)
        return false;

    while (find_next(cur_i, cur_i_left) &&
            find_next(cur_i_k, cur_i_k_left))
    {
        //cout << k << ' ' << cur_i << ' ' << cur_i_k << '\n';
        if (cur_i_k - cur_i > l)
            return false;
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> w >> l;

    a[0] = 1;
    a[w] = 1;

    for (int i = 1; i < w; i++)
    {
        cin >> a[i];
    }

    /*
    int cur = 0, cur_left = 1;
    while (find_next(cur, cur_left))
    {
        cout << cur << ' ' << cur_left << '\n';
    }
    */

    int left = -1, right = 1e9;
    while (right - left > 1)
    {
        //cout << left << ' ' << right << '\n';
        int mid = (left + right) / 2;

        if (can(mid))
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }

    cout << left;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_W = 1e5;
int w, l;
map <int, int> a;

bool find_next(map<int, int>::iterator & cur, int & cur_left)
{
    if (cur_left)
    {
        cur_left--;
        return true;
    }
    else
    {
        cur++;
        if (cur == a.end())
            return false;
        cur_left = cur->second - 1;
        return true;
    }
}

bool can(int k)
{
    auto cur_i = a.begin(), cur_i_k = a.begin();
    int cur_i_left = 1, cur_i_k_left = 1;
    for (int i = 0; i < k; i++)
    {
        if (!find_next(cur_i_k, cur_i_k_left))
        {
            return false;
        }
    }

    if (cur_i_k->first - cur_i->first > l)
        return false;

    while (find_next(cur_i, cur_i_left) &&
            find_next(cur_i_k, cur_i_k_left))
    {
        //cout << k << ' ' << cur_i << ' ' << cur_i_k << '\n';
        if (cur_i_k->first - cur_i->first > l)
            return false;
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> w >> l;

    a[0] = 1;
    a[w] = 1;

    for (int i = 1; i < w; i++)
    {
        int val;
        cin >> val;
        if (val)
            a[i] = val;
    }

    /*
    int cur = 0, cur_left = 1;
    while (find_next(cur, cur_left))
    {
        cout << cur << ' ' << cur_left << '\n';
    }
    */

    int left = -1, right = 1e9;
    while (right - left > 1)
    {
        //cout << left << ' ' << right << '\n';
        int mid = (left + right) / 2;

        if (can(mid))
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }

    cout << left;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_W = 1e5;
int a[MAX_W + 1], used[MAX_W + 1], path[MAX_W + 1];
int w, j_s;

int find_path()
{
    //cout << "IN" << endl;
    int path_len = 0, cur_cord = 0, found = INT_MAX;

    while (cur_cord < w)
    {
        if (cur_cord + j_s >= w)
        {
            cur_cord = w;
            break;
        }
        for (int i = cur_cord + j_s; i >= cur_cord; i--)
        {
            if (i == cur_cord)
            {
                return 0;
            }

            if (a[i] - used[i])
            {
                found = min(found, a[i] - used[i]);
                cur_cord = i;
                path[path_len++] = i;
                break;
            }
        }
    }

    if (cur_cord == w)
    {
        for (int i = 0; i < path_len; i++)
        {
            used[path[i]] += found;
        }

        return found;
    }
    //cout << "OUT" << endl;
    return 0;
}

bool can_pass(long long q)
{
    fill(used + 1, used + w + 1, 0);

    while (q)
    {
        int change = min(q, static_cast<long long>(find_path()));
        if (change == 0)
            break;
        q -= change;
    }

    return q == 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> w >> j_s;
    for (int i = 1; i < w; i++)
    {
        cin >> a[i];
    }

    long long l = -1, r = 1e18;
    while (r - l > 1)
    {
        long long m = (l + r) / 2;

        if (can_pass(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }

    cout << l;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_W = 1e5;
int w, l;
map <int, int> a;

bool find_next(map<int, int>::iterator & cur, int & cur_left, int shift = 1)
{
    if (cur_left >= shift)
    {
        cur_left -= shift;
        return true;
    }
    else
    {
        shift -= cur_left;
        cur++;

        while (shift && cur != a.end())
        {
            if (shift > cur->second)
            {
                shift -= cur->second;
                cur++;
            }
            else
            {
                cur_left = cur->second - shift;
                shift = 0;
            }
        }

        return cur != a.end() && shift == 0;
    }
}

bool can(int k)
{
    auto cur_i = a.begin(), cur_i_k = a.begin();
    int cur_i_left = 1, cur_i_k_left = 1;

    if (!find_next(cur_i_k, cur_i_k_left, k))
    {
        return false;
    }

    if (cur_i_k->first - cur_i->first > l)
        return false;

    while (find_next(cur_i, cur_i_left) &&
            find_next(cur_i_k, cur_i_k_left))
    {
        //cout << k << ' ' << cur_i << ' ' << cur_i_k << '\n';
        if (cur_i_k->first - cur_i->first > l)
            return false;

        int rem = min(cur_i_left, cur_i_k_left);
        cur_i_left -= rem;
        cur_i_k_left -= rem;
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> w >> l;

    a[0] = 1;
    a[w] = 1;

    for (int i = 1; i < w; i++)
    {
        int val;
        cin >> val;
        if (val)
            a[i] = val;
    }

    /*
    int cur = 0, cur_left = 1;
    while (find_next(cur, cur_left))
    {
        cout << cur << ' ' << cur_left << '\n';
    }
    */

    int left = -1, right = 1e9;
    while (right - left > 1)
    {
        //cout << left << ' ' << right << '\n';
        int mid = (left + right) / 2;

        if (can(mid))
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }

    cout << left;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_W = 1e5;
int a[MAX_W + 1], used[MAX_W + 1], path[MAX_W + 1];
int w, j_s;

int find_path()
{
    //cout << "IN" << endl;
    int path_len = 0, cur_cord = 0;

    while (cur_cord < w)
    {
        if (cur_cord + j_s >= w)
        {
            cur_cord = w;
            break;
        }
        for (int i = cur_cord + j_s; i >= cur_cord; i--)
        {
            if (i == cur_cord)
            {
                return 0;
            }

            if (a[i] - used[i])
            {
                cur_cord = i;
                path[path_len++] = i;
                break;
            }
        }
    }

    if (cur_cord == w)
    {
        int found = INT_MAX;
        for (int i = 0; i < path_len; i++)
        {
            found = min(found, a[path[i]] - used[path[i]]);
            used[path[i]] += found;
        }

        return found;
    }
    //cout << "OUT" << endl;
    return 0;
}

bool can_pass(long long q)
{
    fill(used + 1, used + w + 1, 0);

    while (q)
    {
        int change = min(q, static_cast<long long>(find_path()));
        if (change == 0)
            break;
        q -= change;
    }

    return q == 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> w >> j_s;
    for (int i = 1; i < w; i++)
    {
        cin >> a[i];
    }

    long long l = -1, r = 1e18;
    while (r - l > 1)
    {
        long long m = (l + r) / 2;

        if (can_pass(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }

    cout << l;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_W = 1e5;
int w, l;
map <int, int> a;

bool find_next(map<int, int>::iterator & cur, int & cur_left)
{
    if (cur_left)
    {
        cur_left--;
        return true;
    }
    else
    {
        cur++;
        if (cur == a.end())
            return false;
        cur_left = cur->second - 1;
        return true;
    }
}

bool can(int k)
{
    auto cur_i = a.begin(), cur_i_k = a.begin();
    int cur_i_left = 1, cur_i_k_left = 1;
    for (int i = 0; i < k; i++)
    {
        if (!find_next(cur_i_k, cur_i_k_left))
        {
            return false;
        }
    }

    if (cur_i_k->first - cur_i->first > l)
        return false;

    while (find_next(cur_i, cur_i_left) &&
            find_next(cur_i_k, cur_i_k_left))
    {
        //cout << k << ' ' << cur_i << ' ' << cur_i_k << '\n';
        if (cur_i_k->first - cur_i->first > l)
            return false;

        int rem = min(cur_i_left, cur_i_k_left);
        cur_i_left -= rem;
        cur_i_k_left -= rem;
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> w >> l;

    a[0] = 1;
    a[w] = 1;

    for (int i = 1; i < w; i++)
    {
        int val;
        cin >> val;
        if (val)
            a[i] = val;
    }

    /*
    int cur = 0, cur_left = 1;
    while (find_next(cur, cur_left))
    {
        cout << cur << ' ' << cur_left << '\n';
    }
    */

    int left = -1, right = 1e9;
    while (right - left > 1)
    {
        //cout << left << ' ' << right << '\n';
        int mid = (left + right) / 2;

        if (can(mid))
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }

    cout << left;

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<stack>
using namespace std;
#pragma comment(linker, "/STACK:10240000000,10240000000")
#define mem(x,k) memset(x,k,sizeof(x))
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define T_T for(int _=rd(),Case=1;Case<=_;Case++)
#define debug puts("======================")
typedef long long ll;
typedef pair<int,int> pii;
#define CHG ch=getchar()
#define FRD x=bo=0; for(CHG;ch<'0'||ch>'9';CHG) if(ch=='-')bo=1;
#define FR2 for(;ch>='0'&&ch<='9';x=(x<<1)+(x<<3)+ch-'0',CHG);
char ch; int bo;
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
inline void rd(int &x){ FRD FR2 if (bo)x=-x; }
inline void RD(ll &x){ FRD FR2 if (bo)x=-x; }
inline ll RD(){ ll x; RD(x); return x; }
inline int rd(){ int x; rd(x); return x;}
inline void RD(char *s){///scanf %s
    for (CHG;blank(ch);CHG);
    for (;!blank(ch);CHG)*s++=ch; *s=0;
}
inline void RD(char &c){for(CHG;blank(c);CHG);}
template<class T> inline void OT(T x){
    static char buf[20];
    char *p1=buf;if(!x)*p1++='0';if (x<0)putchar('-'),x=-x;
    while(x)*p1++=x%10+'0',x/=10;
    while(p1--!=buf)putchar(*p1);
}
#define pe() puts("")
#define pk() putchar(' ')
#define wt(x) OT(x),pe();
#define wl(a,n) rep(_i,n) OT(a[_i]),putchar(" \n"[_i==n-1]);
const int maxn = 1e5 + 8;
int a[maxn];
int b[maxn];
void inner_adjust(int l ,int r){
    int p1 = l,p2 = r;
    while(p2 > p1){
        int c = a[p2];
        if(c<0)debug;
        if(c >= b[p1]){
            b[p2] += b[p1];
            b[p1] = 0;
            p1 ++;
        }else{
            b[p1] -= c;
            b[p2] += c;
            p2 --;
        }
    }
    return ;
}
void deal(int l, int r, int L, int R, int lim){
   int oR = R, oL = L;
   while(r>=l){
        R = min(r + lim, R);
        while(R>=L){
            int c = a[R];
            if(b[r]<=c){
                b[R] += b[r];
                a[R] -= b[r];
                b[r] = 0;
                break;
            }else{
                b[R] += c;
                a[R] -= c;
                b[r] -= c;
                R--;
            }
        }
        r--;
    }
    inner_adjust(oL,oR);
    return ;
}

int main(){
    int w=rd(),le=rd();
    for(int i=2;i<=w;i++)rd(a[i]);
    mem(b,0);
    b[1] = 1e4 * le;
    w++;
    a[w] = b[1];

    int l=1,r=1,L,R;
    while(1){
        L = r+1, R = min(w,L+le-1);
      // wl((b+1), w);
       //printf("%d %d %d %d\n",l,r,L,R);
        deal(l,r,L,R,le);
        if(R==w){
            if(L<w) deal(L,R-1,w,w, le);
            break;
        }
        l = L,r =R;
    }
    wt(b[w]);
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<stack>
using namespace std;
#pragma comment(linker, "/STACK:10240000000,10240000000")
#define mem(x,k) memset(x,k,sizeof(x))
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define T_T for(int _=rd(),Case=1;Case<=_;Case++)
#define debug puts("======================")
typedef long long ll;
typedef pair<int,int> pii;
#define CHG ch=getchar()
#define FRD x=bo=0; for(CHG;ch<'0'||ch>'9';CHG) if(ch=='-')bo=1;
#define FR2 for(;ch>='0'&&ch<='9';x=(x<<1)+(x<<3)+ch-'0',CHG);
char ch; int bo;
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
inline void rd(int &x){ FRD FR2 if (bo)x=-x; }
inline void RD(ll &x){ FRD FR2 if (bo)x=-x; }
inline ll RD(){ ll x; RD(x); return x; }
inline int rd(){ int x; rd(x); return x;}
inline void RD(char *s){///scanf %s
    for (CHG;blank(ch);CHG);
    for (;!blank(ch);CHG)*s++=ch; *s=0;
}
inline void RD(char &c){for(CHG;blank(c);CHG);}
template<class T> inline void OT(T x){
    static char buf[20];
    char *p1=buf;if(!x)*p1++='0';if (x<0)putchar('-'),x=-x;
    while(x)*p1++=x%10+'0',x/=10;
    while(p1--!=buf)putchar(*p1);
}
#define pe() puts("")
#define pk() putchar(' ')
#define wt(x) OT(x),pe();
#define wl(a,n) rep(_i,n) OT(a[_i]),putchar(" \n"[_i==n-1]);
const int maxn = 1e5 + 8;
int a[maxn];
int b[maxn];
void inner_adjust(int l ,int r){
    int p1 = l,p2 = r;
    while(p2 > p1){
        int c = a[p2] - b[p2];
        if(c >= b[p1]){
            b[p1] = 0;
            b[p2] += b[p1];
            p1 ++;
        }else{
            b[p1] -= c;
            b[p2] += c;
            p2 --;
        }
    }
    return ;
}
void deal(int l, int r, int L, int R, int lim){
    while(r>=l){
        R = min(r + lim, R);
        while(R>=L){
            int c = a[R] - b[R];
            if(b[r]<=c){
                b[R] += b[r];
                a[R] -= b[r];
                b[r] = 0;
                break;
            }else{
                b[R] += c;
                a[R] -= c;
                b[r] -= c;
                R--;
            }
        }
        r--;
    }
    inner_adjust(L,R);
    return ;
}

int main(){
    int w=rd(),le=rd();
    for(int i=2;i<=w;i++)rd(a[i]);
    mem(b,0);
    b[1] = 1e4 * le;
    w++;
    a[w] = b[1];

    int l=1,r=1,L,R;
    while(1){
        L = r+1, R = min(w,L+le-1);
      //  wl((b+1), w);
        deal(l,r,L,R,le);
        if(R==w){
            if(L<w) deal(L,R-1,w,w, le);
            break;
        }
        l = L,r =R;
    }
    wt(b[w]);
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<stack>
using namespace std;
#pragma comment(linker, "/STACK:10240000000,10240000000")
#define mem(x,k) memset(x,k,sizeof(x))
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define T_T for(int _=rd(),Case=1;Case<=_;Case++)
#define debug puts("======================")
typedef long long ll;
typedef pair<int,int> pii;
#define CHG ch=getchar()
#define FRD x=bo=0; for(CHG;ch<'0'||ch>'9';CHG) if(ch=='-')bo=1;
#define FR2 for(;ch>='0'&&ch<='9';x=(x<<1)+(x<<3)+ch-'0',CHG);
char ch; int bo;
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
inline void rd(int &x){ FRD FR2 if (bo)x=-x; }
inline void RD(ll &x){ FRD FR2 if (bo)x=-x; }
inline ll RD(){ ll x; RD(x); return x; }
inline int rd(){ int x; rd(x); return x;}
inline void RD(char *s){///scanf %s
    for (CHG;blank(ch);CHG);
    for (;!blank(ch);CHG)*s++=ch; *s=0;
}
inline void RD(char &c){for(CHG;blank(c);CHG);}
template<class T> inline void OT(T x){
    static char buf[20];
    char *p1=buf;if(!x)*p1++='0';if (x<0)putchar('-'),x=-x;
    while(x)*p1++=x%10+'0',x/=10;
    while(p1--!=buf)putchar(*p1);
}
#define pe() puts("")
#define pk() putchar(' ')
#define wt(x) OT(x),pe();
#define wl(a,n) rep(_i,n) OT(a[_i]),putchar(" \n"[_i==n-1]);
const int maxn = 1e5 + 8;
int a[maxn];
int b[maxn];
void deal(int l, int r, int L, int R, int lim){
    while(r>=l){
        R = min(r + lim, R);
        while(R>=L){
            int c = a[R] - b[R];
            if(b[r]<=c){
                b[R] += b[r];
                a[R] -= b[r];
                b[r] = 0;
                break;
            }else{
                b[R] += c;
                a[R] -= c;
                b[r] -= c;
                R--;
            }
        }
        r--;
    }
    return ;
}
int main(){
    int w=rd(),le=rd();
    for(int i=2;i<=w;i++)rd(a[i]);
    mem(b,0);
    b[1] = 1e4 * le;
    w++;
    a[w] = b[1];

    int l=1,r=1,L,R;
    while(1){
        L = r+1, R = min(w,L+le-1);
      //  wl((b+1), w);
        deal(l,r,L,R,le);
        if(R==w){
            if(L<w) deal(L,R-1,w,w, le);
            break;
        }
        l = L,r =R;
    }
    wt(b[w]);
    return 0;
}


#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> c(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d", &c[i]);
  }
  int cnt = 0;
  for (int i = 0; i < m; ++i) cnt += c[i];
  int space = cnt;
  for (int i = m; i < n - 1; ++i) {
    space = space - c[i - m] + c[i];
    cnt = min(cnt, space);
  }
  printf("%d\n", cnt);
  return 0;
}


#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct maxflow {
  struct edge;
  using iter = vector<edge>::iterator;
  struct edge {
    int v, c;
    iter nxt;
  };
  vector<edge> pool;
  iter last, null;
  vector<iter> a, idx;
  vector<int> d;
  iter new_edge(int v, int c, iter nxt) {
    iter p = last++;
    *p = edge{v, c, nxt};
    return p;
  }
  void add_edge(int u, int v, int c) {
    // trace(u, v, c);
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, 0, a[v]);
  }
  void add_bidirection_edge(int u, int v, int c) {
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, c, a[v]);
  }
  iter dual(iter p) {
    return pool.begin() + ((p - pool.begin()) ^ 1);
  }
  int augment(int u, int t, int bound) {
    // trace(u, t, bound);
    if (u == t) return bound;
    int ret = 0;
    // current arc optimization
    for (iter it = a[u]; it != null && ret < bound; it = it->nxt) {
      if (it->c && d[it->v] == d[u] + 1) {
        // trace(u, it->v, it->c);
        int aug = augment(it->v, t, min(it->c, bound - ret));
        ret += aug;
        it->c -= aug;
        dual(it)->c += aug;
      }
    }
    if (ret == 0) d[u] = -1;
    return ret;
  }
  bool path(int s, int t) {
    fill(d.begin(), d.end(), -1);
    d[s] = 0;
    queue<int> Q;
    Q.push(s);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (iter it = a[u]; it != null; it = it->nxt) {
        if (it->c && d[it->v] == -1) {
          Q.push(it->v);
          d[it->v] = d[u] + 1;
          if (it->v == t) return true;
        }
      }
    }
    return false;
  }
  void init(int n, int m) {
    pool.resize(m << 1);
    last = pool.begin();
    null = pool.end();
    a.assign(n, null);
    idx.assign(n, null);
    d.resize(n);
  }
  int dinic(int s, int t) {
    int ret = 0;
    while (path(s, t)) {
      // // current arc optimization
      // copy(a.begin(), a.end(), idx.begin());
      while (int aug = augment(s, t, INF)) {
        ret += aug;
      }
    }
    return ret;
  }
};

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  maxflow flow;
  n += 1;
  flow.init(2 * n, 3 * n);
  int s = 0, t = 2 * n - 1;
  // trace(len, s, t);
  for (int i = 0; i < n; ++i) {
    if (i > 0 && i < n - 1) {
      int C;
      scanf("%d", &C);
      if (C) flow.add_edge(i * 2, i * 2 + 1, C);
    } else {
      flow.add_edge(i * 2, i * 2 + 1, INF);
    }
    if (i > 0) flow.add_edge(i * 2, i * 2 - 2, INF);
    if (i - m >= 0) {
      // trace(i - m, i);
      flow.add_edge((i - m) * 2 + 1, i * 2, INF);
    }
    if (i + m >= n - 1) {
      flow.add_edge(i * 2 + 1, t, INF);
    }
  }
  auto ret = flow.dinic(s, t);
  printf("%d\n", ret);
  return 0;
}


#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct maxflow {
  struct edge;
  using iter = vector<edge>::iterator;
  struct edge {
    int v, c;
    iter nxt;
  };
  vector<edge> pool;
  iter last, null;
  vector<iter> a, idx;
  vector<int> d;
  iter new_edge(int v, int c, iter nxt) {
    iter p = last++;
    *p = edge{v, c, nxt};
    return p;
  }
  void add_edge(int u, int v, int c) {
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, 0, a[v]);
  }
  void add_bidirection_edge(int u, int v, int c) {
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, c, a[v]);
  }
  iter dual(iter p) {
    return pool.begin() + ((p - pool.begin()) ^ 1);
  }
  int augment(int u, int t, int bound) {
    if (u == t) return bound;
    int ret = 0;
    // current arc optimization
    for (iter& it = idx[u]; it != null && ret < bound; it = it->nxt) {
      if (it->c && d[it->v] == d[u] + 1) {
        int aug = augment(it->v, t, min(it->c, bound - ret));
        ret += aug;
        it->c -= aug;
        dual(it)->c += aug;
      }
    }
    if (ret == 0) d[u] = -1;
    return ret;
  }
  bool path(int s, int t) {
    fill(d.begin(), d.end(), -1);
    d[s] = 0;
    queue<int> Q;
    Q.push(s);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (iter it = a[u]; it != null; it = it->nxt) {
        if (it->c && d[it->v] == -1) {
          Q.push(it->v);
          d[it->v] = d[u] + 1;
          if (it->v == t) return true;
        }
      }
    }
    return false;
  }
  void init(int n, int m) {
    pool.resize(m << 1);
    last = pool.begin();
    null = pool.end();
    a.assign(n, null);
    idx.assign(n, null);
    d.resize(n);
  }
  int dinic(int s, int t) {
    int ret = 0;
    while (path(s, t)) {
      // current arc optimization
      copy(a.begin(), a.end(), idx.begin());
      while (int aug = augment(s, t, INF)) {
        ret += aug;
      }
    }
    return ret;
  }
};

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  maxflow flow;
  int len = n + m;
  flow.init(2 * len, 3 * len);
  int s = 0, t = 2 * n + 1;
  for (int i = 0; i < len; ++i) {
    if (i > 0 && i < n - 1) {
      int C;
      scanf("%d", &C);
      if (C) flow.add_edge(i * 2, i * 2 + 1, C);
    } else {
      flow.add_edge(i * 2, i * 2 + 1, INF);
    }
    if (i > 0) flow.add_edge(i * 2, i * 2 - 2, INF);
    if (i - m >= 0) {
      // trace(i - m, i);
      flow.add_edge((i - m) * 2 + 1, i * 2, INF);
    }
  }
  auto ret = flow.dinic(s, t);
  printf("%d\n", ret);
  return 0;
}


#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct maxflow {
  struct edge;
  using iter = vector<edge>::iterator;
  struct edge {
    int v, c;
    iter nxt;
  };
  vector<edge> pool;
  iter last, null;
  vector<iter> a, idx;
  vector<int> d;
  iter new_edge(int v, int c, iter nxt) {
    iter p = last++;
    *p = edge{v, c, nxt};
    return p;
  }
  void add_edge(int u, int v, int c) {
    // trace(u, v, c);
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, 0, a[v]);
  }
  void add_bidirection_edge(int u, int v, int c) {
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, c, a[v]);
  }
  iter dual(iter p) {
    return pool.begin() + ((p - pool.begin()) ^ 1);
  }
  int augment(int u, int t, int bound) {
    // trace(u, t, bound);
    if (u == t) return bound;
    int ret = 0;
    // current arc optimization
    for (iter& it = idx[u]; it != null && ret < bound; it = it->nxt) {
      if (it->c && d[it->v] == d[u] + 1) {
        // trace(u, it->v, it->c);
        int aug = augment(it->v, t, min(it->c, bound - ret));
        ret += aug;
        it->c -= aug;
        dual(it)->c += aug;
      }
    }
    if (ret == 0) d[u] = -1;
    return ret;
  }
  bool path(int s, int t) {
    fill(d.begin(), d.end(), -1);
    static int pre[1000];
    fill(pre, pre + 1000, -1);
    d[s] = 0;
    queue<int> Q;
    Q.push(s);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (iter it = a[u]; it != null; it = it->nxt) {
        if (it->c && d[it->v] == -1) {
          Q.push(it->v);
          d[it->v] = d[u] + 1;
          pre[it->v] = u;
          if (it->v == t) return true;
        }
      }
    }
    return false;
  }
  void init(int n, int m) {
    pool.resize(m << 1);
    last = pool.begin();
    null = pool.end();
    a.assign(n, null);
    idx.assign(n, null);
    d.resize(n);
  }
  int dinic(int s, int t) {
    int ret = 0;
    while (path(s, t)) {
      // current arc optimization
      copy(a.begin(), a.end(), idx.begin());
      while (int aug = augment(s, t, INF)) {
        ret += aug;
      }
    }
    return ret;
  }
};

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  maxflow flow;
  int len = n + m;
  flow.init(2 * len, 3 * len);
  int s = 0, t = 2 * n + 1;
  // trace(len, s, t);
  for (int i = 0; i < len; ++i) {
    if (i > 0 && i < n) {
      int C;
      scanf("%d", &C);
      if (C) flow.add_edge(i * 2, i * 2 + 1, C);
    } else {
      flow.add_edge(i * 2, i * 2 + 1, INF);
    }
    if (i > 0) flow.add_edge(i * 2, i * 2 - 2, INF);
    if (i - m >= 0) {
      // trace(i - m, i);
      flow.add_edge((i - m) * 2 + 1, i * 2, INF);
    }
  }
  auto ret = flow.dinic(s, t);
  printf("%d\n", ret);
  return 0;
}


#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct maxflow {
  struct edge;
  using iter = vector<edge>::iterator;
  struct edge {
    int v, c;
    iter nxt;
  };
  vector<edge> pool;
  iter last, null;
  vector<iter> a, idx;
  vector<int> d;
  iter new_edge(int v, int c, iter nxt) {
    iter p = last++;
    *p = edge{v, c, nxt};
    return p;
  }
  void add_edge(int u, int v, int c) {
    // trace(u, v, c);
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, 0, a[v]);
  }
  void add_bidirection_edge(int u, int v, int c) {
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, c, a[v]);
  }
  iter dual(iter p) {
    return pool.begin() + ((p - pool.begin()) ^ 1);
  }
  int augment(int u, int t, int bound) {
    // trace(u, t, bound);
    if (u == t) return bound;
    int ret = 0;
    // current arc optimization
    for (iter& it = idx[u]; it != null && ret < bound; it = it->nxt) {
      if (it->c && d[it->v] == d[u] + 1) {
        // trace(u, it->v, it->c);
        int aug = augment(it->v, t, min(it->c, bound - ret));
        ret += aug;
        it->c -= aug;
        dual(it)->c += aug;
      }
    }
    if (ret == 0) d[u] = -1;
    return ret;
  }
  bool path(int s, int t) {
    fill(d.begin(), d.end(), -1);
    d[s] = 0;
    queue<int> Q;
    Q.push(s);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (iter it = a[u]; it != null; it = it->nxt) {
        if (it->c && d[it->v] == -1) {
          Q.push(it->v);
          d[it->v] = d[u] + 1;
          if (it->v == t) return true;
        }
      }
    }
    return false;
  }
  void init(int n, int m) {
    pool.resize(m << 1);
    last = pool.begin();
    null = pool.end();
    a.assign(n, null);
    idx.assign(n, null);
    d.resize(n);
  }
  int dinic(int s, int t) {
    int ret = 0;
    while (path(s, t)) {
      // current arc optimization
      copy(a.begin(), a.end(), idx.begin());
      while (int aug = augment(s, t, INF)) {
        ret += aug;
      }
    }
    return ret;
  }
};

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  maxflow flow;
  int len = n + m;
  flow.init(2 * len, 3 * len);
  int s = 0, t = 2 * n + 1;
  // trace(len, s, t);
  for (int i = 0; i < len; ++i) {
    if (i > 0 && i < n) {
      int C;
      scanf("%d", &C);
      if (C) flow.add_edge(i * 2, i * 2 + 1, C);
    } else {
      flow.add_edge(i * 2, i * 2 + 1, INF);
    }
    if (i > 0) flow.add_edge(i * 2, i * 2 - 2, INF);
    if (i - m >= 0) {
      // trace(i - m, i);
      flow.add_edge((i - m) * 2 + 1, i * 2, INF);
    }
  }
  auto ret = flow.dinic(s, t);
  printf("%d\n", ret);
  return 0;
}


#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct maxflow {
  struct edge;
  using iter = vector<edge>::iterator;
  struct edge {
    int v, c;
    iter nxt;
  };
  vector<edge> pool;
  iter last, null;
  vector<iter> a, idx;
  vector<int> d;
  iter new_edge(int v, int c, iter nxt) {
    iter p = last++;
    *p = edge{v, c, nxt};
    return p;
  }
  void add_edge(int u, int v, int c) {
    // trace(u, v, c);
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, 0, a[v]);
  }
  void add_bidirection_edge(int u, int v, int c) {
    a[u] = new_edge(v, c, a[u]);
    a[v] = new_edge(u, c, a[v]);
  }
  iter dual(iter p) {
    return pool.begin() + ((p - pool.begin()) ^ 1);
  }
  int augment(int u, int t, int bound) {
    // trace(u, t, bound);
    if (u == t) return bound;
    int ret = 0;
    // current arc optimization
    for (iter& it = idx[u]; it != null && ret < bound; it = it->nxt) {
      if (it->c && d[it->v] == d[u] + 1) {
        // trace(u, it->v, it->c);
        int aug = augment(it->v, t, min(it->c, bound - ret));
        ret += aug;
        it->c -= aug;
        dual(it)->c += aug;
      }
    }
    if (ret == 0) d[u] = -1;
    return ret;
  }
  bool path(int s, int t) {
    fill(d.begin(), d.end(), -1);
    d[s] = 0;
    queue<int> Q;
    Q.push(s);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (iter it = a[u]; it != null; it = it->nxt) {
        if (it->c && d[it->v] == -1) {
          Q.push(it->v);
          d[it->v] = d[u] + 1;
          if (it->v == t) return true;
        }
      }
    }
    return false;
  }
  void init(int n, int m) {
    pool.resize(m << 1);
    last = pool.begin();
    null = pool.end();
    a.assign(n, null);
    idx.assign(n, null);
    d.resize(n);
  }
  int dinic(int s, int t) {
    int ret = 0;
    while (path(s, t)) {
      // current arc optimization
      copy(a.begin(), a.end(), idx.begin());
      while (int aug = augment(s, t, INF)) {
        ret += aug;
      }
    }
    return ret;
  }
};

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  maxflow flow;
  n += 1;
  flow.init(2 * n, 3 * n);
  int s = 0, t = 2 * n - 1;
  // trace(len, s, t);
  for (int i = 0; i < n; ++i) {
    if (i > 0 && i < n - 1) {
      int C;
      scanf("%d", &C);
      if (C) flow.add_edge(i * 2, i * 2 + 1, C);
    } else {
      flow.add_edge(i * 2, i * 2 + 1, INF);
    }
    if (i > 0) flow.add_edge(i * 2, i * 2 - 2, INF);
    if (i - m >= 0) {
      // trace(i - m, i);
      flow.add_edge((i - m) * 2 + 1, i * 2, INF);
    }
    if (i + m >= n - 1) {
      flow.add_edge(i * 2 + 1, t, INF);
    }
  }
  auto ret = flow.dinic(s, t);
  printf("%d\n", ret);
  return 0;
}


//author: DumbBrick27
//Created on: 08.13.20
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) {
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) {
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef D
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int mxN = 1e5 + 10;
int n, l, a[mxN];

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> l;
    int sum = 0;
    for(int i=0; i < n-1; i++) cin >> a[i];
    for(int i =0; i < l; i++){
        sum += a[i];
    }
    dbg(sum);
    int mi = 1e9;
    ckmin(sum , mi);
    for(int i = l; i < n-1; i++){
        sum -= a[i-l];
        sum += a[i];
        ckmin(mi, sum);
        dbg(sum);
    }
    cout << mi << nl;
}


//author: DumbBrick27
//Created on: 08.13.20
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) {
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) {
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef D
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int mxN = 1e5 + 10;
int n, l, a[mxN];

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> l;
    int sum = 0;
    for(int i=0; i < n-1; i++) cin >> a[i];
    for(int i =0; i < l; i++){
        sum += a[i];
    }
    dbg(sum);
    int mi = 1e9;
    ckmin(mi, sum);
    for(int i = l; i < n-1; i++){
        sum -= a[i-l];
        sum += a[i];
        ckmin(mi, sum);
        dbg(sum);
    }
    cout << mi << nl;
}


//author: DumbBrick27
//Created on: 08.13.20
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) {
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) {
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef D
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int mxN = 1e5 + 10;
int n, l, a[mxN];

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> l;
    int sum = 0;
    for(int i=0; i < n-1; i++) cin >> a[i];
    for(int i =0; i < l; i++){
        sum += a[i];
    }
    dbg(sum);
    int mi = 1e9;
    for(int i = l; i < n-1; i++){
        sum -= a[i-l];
        sum += a[i];
        ckmin(mi, sum);
        dbg(sum);
    }
    cout << mi << nl;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

int w, l, x, sum, ans;
vector <int> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> w >> l;
    for(int i = 1 ; i < w && cin >> x ; i++)
        a.push_back(x);
    for(int i = 0 ; i < l ; i++)
        sum += a[i];
    ans = sum;
    for(int i = l ; i < w - 1 ; i++){
        sum += a[i];
        sum -= a[i - l];
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll l, w, x, ans;
vector <int> a, v;
set <int> s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    a.push_back(0);
    cin >> w >> l;
    for(int i = 1 ; i < w && cin >> x ; i++){
        a.push_back(x);
        if(x) s.insert(i);
    }
    while(1){
        int cur = 0;
        while(1){
            auto it = s.upper_bound(cur + l);
            if(it != s.begin()) it--;
            if(v.size() && *it == v.back()) break;
            v.push_back(*it);
            cur = *it;
            if(*it + l >= w) break;
        }
        if(v.back() + l < w) break;
        int mn = 1e5;
        for(auto &i : v)
            mn = min(mn, a[i]);
        for(auto &i : v){
            a[i] -= mn;
            if(a[i] == 0) s.erase(i);
        }
        ans += mn;
        v.clear();
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll l, w, x, ans;
vector <int> a, v;
set <int> s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    a.push_back(0);
    cin >> w >> l;
    for(int i = 1 ; i < w && cin >> x ; i++){
        a.push_back(x);
        if(x) s.insert(i);
    }
    while(1){
        int cur = 0;
        while(1){
            auto it = s.upper_bound(cur + l);
            if(it == s.begin() && *it > cur + l) break;
            if(it != s.begin()) it--;
            if(v.size() && *it == v.back()) break;
            v.push_back(*it);
            cur = *it;
            if(*it + l >= w) break;
        }
        if(v.size() == 0) break;
        if(v.back() + l < w) break;
        int mn = 1e5;
        for(auto &i : v)
            mn = min(mn, a[i]);
        for(auto &i : v){
            a[i] -= mn;
            if(a[i] == 0) s.erase(i);
        }
        ans += mn;
        v.clear();
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll l, w, x, ans;
vector <int> a, v;
set <int> s;

int main(){
    a.push_back(0);
    cin >> w >> l;
    scanf("%I64d %I64d", &w, &l);
    for(int i = 1 ; i < w && scanf("%I64d", &x) ; i++){
        a.push_back(x);
        if(x) s.insert(i);
    }
    while(1){
        int cur = 0;
        while(1){
            auto it = s.upper_bound(cur + l);
            if(it == s.begin() && *it > cur + l) break;
            if(it != s.begin()) it--;
            if(v.size() && *it == v.back()) break;
            v.push_back(*it);
            cur = *it;
            if(*it + l >= w) break;
        }
        if(v.size() == 0) break;
        if(v.back() + l < w) break;
        int mn = 1e5;
        for(auto &i : v)
            mn = min(mn, a[i]);
        for(auto &i : v){
            a[i] -= mn;
            if(a[i] == 0) s.erase(i);
        }
        ans += mn;
        v.clear();
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll l, w, x, ans;
vector <int> a, v;
set <int> s;

int main(){
    a.push_back(0);
    scanf("%I64d %I64d", &w, &l);
    for(int i = 1 ; i < w && scanf("%I64d", &x) ; i++){
        a.push_back(x);
        if(x) s.insert(i);
    }
    while(1){
        int cur = 0;
        while(1){
            auto it = s.upper_bound(cur + l);
            if(it == s.begin() && *it > cur + l) break;
            if(it != s.begin()) it--;
            if(v.size() && *it == v.back()) break;
            v.push_back(*it);
            cur = *it;
            if(*it + l >= w) break;
        }
        if(v.size() == 0) break;
        if(v.back() + l < w) break;
        int mn = 1e5;
        for(auto &i : v)
            mn = min(mn, a[i]);
        for(auto &i : v){
            a[i] -= mn;
            if(a[i] == 0) s.erase(i);
        }
        ans += mn;
        v.clear();
    }
    printf("%I64d\n", ans);
    return 0;
}


#include<stdio.h>

#define maxn 100010

int p[maxn], f[maxn];

int i,j,n,m;

int main() {
  scanf("%d %d", &n, &m);
  for(i=1;i<n;i++) {
    scanf("%d", &p[i]);
  }
  int i, ans = 0, delta;

  for(i=1;i<=m;i++)
    f[i]=p[i];
  j=1+m;
  for(i=1;i<n;i++) {
    if(i+m>=n) {ans+=f[i]; continue;}

    while(j<=i+m && f[i] > 0) {
      delta = p[j] - f[j];
      if(delta > f[i]) delta=f[i];
      f[i]-=delta;
      f[j] += delta;
      if(f[j]==p[j])j++;
    }

  }

  printf("%d\n", ans);
  return 0;
}


#include<stdio.h>

#define maxn 100010

int p[maxn];

bool checked[maxn];

int i,j,n,m;

int blocking_flow(int a, int flow) {
  if(a+m>=n) {
    p[a]-=flow;
    if(p[a]==0) checked[a]=true;
    return flow;
  }
  if(flow==0) {
    return 0;
  }
  int i, j, total=0;
  for(i=a+m;i>a;i--) if(!checked[i]) {
    j=blocking_flow(i, flow>p[i]?p[i]:flow);
    flow-=j;
    total+=j;
  }
  p[a]-=total;
  if(p[a]==0 || flow) {
    checked[a]=true;
  }
  return total;
}

int main() {
  scanf("%d %d", &n, &m);
  for(i=1;i<n;i++) {
    scanf("%d", &p[i]);
    if(p[i]==0) checked[i]=true;
  }
  printf("%d\n", blocking_flow(0, 1000000000));
  return 0;
}