#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 5;
int n, m;
long long a[MN], L, R;
long long b[MN];
bool ok(long long t) {
  int beg = 1;
  for (int i = 1; i <= n; ++i) b[i] = a[i];
  for (int i = 1; i <= m; ++i) {
    long long nowt = beg;
    for (int j = beg; j <= n; ++j) {
      if (nowt > t) break;
      if (nowt + b[j] <= t) {
        nowt += b[j];
        b[j] = 0;
        beg++;
      } else {
        b[j] -= t - nowt;
        break;
      }
      nowt++;
    }
  }
  if (beg <= n)
    while (beg <= n && b[beg] == 0) ++beg;
  if (beg > n) return true;
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
  }
  L = 0ll;
  R = (1ll << 50);
  while (L <= R) {
    long long mid = (L + R) >> 1;
    if (ok(mid))
      R = mid - 1;
    else
      L = mid + 1;
  }
  cout << L << endl;
  return 0;
}
