#include <bits/stdc++.h>
int n, m;
int a[100002], b[100002];
bool check(const long long mid) {
  std::copy(a + 1, a + 1 + n, b + 1);
  int last = n;
  while (last > 0 && b[last] == 0) last--;
  int dead = 0;
  for (int i = 0; i < m; i++) {
    while (b[dead] == 0) dead++;
    long long remain = mid - dead;
    while (remain > 0 && dead <= last) {
      if (remain < b[dead]) {
        b[dead] -= remain;
        remain = 0;
      } else {
        remain -= b[dead];
        b[dead] = 0;
        dead++;
        remain--;
      }
    }
    if (b[last] == 0) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  long long left = 0, right = 0x7f7f7f7f7f7f7f7f;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (a[i] > 0) left = i;
    right += a[i];
  }
  long long ans;
  while (left <= right) {
    long long middle = (left + right) >> 1;
    if (check(middle)) {
      ans = middle;
      right = middle - 1;
    } else
      left = middle + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
