#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <bitset>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define for0(i, n) for (ll i = 0; i < n; ++i)
#define for1(i, n) for (ll i = 1; i <= n; ++i)
#define fora(i, v) for (auto i : v)
#define ft first
#define sd second
#define pk push_back
#define pok pop_back
#define ret return
#define con continue
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using pll = pair <ll, ll>;
using vll = vector <ll>;
using vpll = vector <pll>;
using vvll = vector <vll>;
using pi = pair <int, int>;
using vi = vector <int>;
using vpi = vector <pi>;
using vvi = vector <vector <int>>;

const ll N = 5e5;

ll n, k, m, ans = 0;
ll arr[N + 1];

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	for1(i, n)
		cin >> arr[i];
	for1(i, k - 1)
		ans += (arr[i] + 1);
	m = 0;
	for (ll i = k; i <= n; ++i)
		m = max(m, arr[i] + i + 1 - k);
	cout << ans + m << "\n";
	ret 0;
}