#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC target("avx2")

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ost = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
template<long long N, class T = long long>
using pii = array<T, N>;

constexpr ll mxn = 5e5;//5e5;

int main() {
    ll n, k;
    ll arr[mxn]{};

    cin >> n >> k;
    for (ll i = 0; i < n; ++i) cin >> arr[i];

    ll out = k;
    for (ll i = 0; i < k - 1; ++i)
        out += arr[i];
    ll tmx = arr[k - 1];
    for (ll i = k; i < n; ++i) {
            tmx = max(tmx, arr[i] + i - k + 1);
    }

    cout << out + tmx;

    return 0;
}
