#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long a[N], b[N];
int main() {
  std::ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long tot = 0;
  long long ma = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    tot += a[i];
    if (a[i] != 0) {
      ma = i + 1;
    }
  }
  long long l = 0, r = n + tot;
  while (l < r) {
    long long mi = (l + r) / 2;
    bool pos = false;
    if (ma <= mi) {
      for (int i = 0; i < ma; ++i) b[i] = a[i];
      int curm = m - 1;
      long long curmi = mi - ma;
      int i;
      for (i = ma - 1; i >= 0;) {
        if (b[i]) {
          if (curmi <= 0) {
            if (curm == 0) break;
            curmi = mi - (i + 1);
            curm--;
          }
          long long tmp = min(curmi, b[i]);
          curmi -= tmp;
          b[i] -= tmp;
        }
        if (b[i] == 0) {
          --i;
        }
      }
      if (i == -1) pos = true;
    }
    if (pos)
      r = mi;
    else
      l = mi + 1;
  }
  cout << l << endl;
  return 0;
}
