#include <bits/stdc++.h>
using namespace std;
const int maxn = 110005;
long long arr[maxn], arr1[maxn], n, m;
int judge(long long x) {
  memcpy(arr1, arr, sizeof(arr));
  long long i = n, countt = 1, t = 0;
  while (i >= 1 && arr1[i] <= 0) --i;
  while (countt <= m) {
    t = x - i;
    while (t > 0) {
      if (t >= arr1[i]) {
        t = t - arr1[i];
        arr1[i] = 0;
        i--;
        if (i < 1) return 1;
      } else {
        arr1[i] = arr1[i] - t;
        t = 0;
      }
    }
    ++countt;
  }
  return 0;
}
long long aa(long long u) {
  long long p = n, q;
  while (!arr[p]) p--;
  q = arr[p];
  for (long long i = 1; i <= m; i++) {
    long long o = u;
    o -= p;
    if (o <= 0) return 0;
    while (o) {
      if (o >= q) {
        o -= q;
        p--;
        while (!arr[p]) p--;
        if (p < 1) return 1;
        q = arr[p];
      } else {
        q -= o;
        break;
      }
    }
  }
  return 0;
}
int main() {
  long long left, right, ans, mid;
  scanf("%lld%lld", &n, &m);
  left = 0;
  right = 1e18;
  ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
  }
  while (left <= right) {
    mid = (left + right) / 2;
    if (aa(mid)) {
      ans = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
