#include <bits/stdc++.h>
using namespace std;
int org[100001];
int pile[100001];
int main() {
  int n, M;
  cin >> n >> M;
  for (int i = 1; i <= n; ++i) cin >> org[i];
  int64_t l = 0, h = 9999999999999999LL;
  while (l < h) {
    int64_t make_pair = (l + h) / 2;
    int i = n;
    bool ok = 1;
    for (int j = 1; j <= n; ++j) pile[j] = org[j];
    for (int s = 0; s < M && ok && i > 0; ++s) {
      int64_t time = make_pair;
      while (i >= 1 && pile[i] == 0) i--;
      time -= i;
      if (time < 0)
        ok = 0;
      else {
        int x = min((int64_t)pile[i], time);
        time -= x, pile[i] -= x;
        while (i > 0 && time > 0) {
          while (i >= 1 && pile[i] == 0) i--;
          int64_t dm = min((int64_t)pile[i], time);
          pile[i] -= dm;
          time -= dm;
        }
      }
    }
    for (int j = 1; j <= n; ++j) ok &= pile[j] == 0;
    if (ok)
      h = make_pair;
    else
      l = make_pair + 1;
  }
  cout << h << "\n";
  return 0;
}
