#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v;
bool valid(long long t) {
  int T = 0;
  for (int i = 0; i < n; ++i)
    if (v[i]) T = i + 1;
  vector<int> V = v;
  long long curt = t - T, curst = k - 1;
  int i = T - 1;
  while (i >= 0) {
    if (V[i] <= curt)
      curt -= V[i], i--;
    else {
      V[i] -= curt;
      curt = t - i - 1;
      curst--;
    }
    if (curst < 0) return false;
  }
  return true;
}
int main() {
  cin >> n >> k;
  v.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  long long st = 0, en = 1000000000000000LL;
  while (en > st) {
    long long mid = (st + en) / 2LL;
    if (valid(mid))
      en = mid;
    else
      st = mid + 1;
  }
  cout << en << endl;
  return 0;
}
