#ifndef LOCAL
  // #pragma GCC optimize("Ofast,unroll-loops")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#ifndef LOCAL
  // #pragma GCC target("avx,avx2,fma")
#endif

using namespace std;
using namespace __gnu_pbds;

using ll = long long;

void solve() {
  int n, k;
  cin >> n >> k;
  deque<int> a(n);
  for (auto& it : a) cin >> it;
  ll ans = 0;
  for (int i = 0; i < k - 1; ++i) {
    ans += a[0] + 1;
    a.pop_front();
  }
  ll mx = 0;
  for (int i = 0; i < (int)a.size(); ++i) mx = max(mx, a[i] + i + 1);
  cout << ans + mx << '\n';
}

signed main() {
  // freopen("in", "r", stdin);
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  // cin >> t;
  for (int i = 0; i < t; ++i) {
    solve();
  }
}