#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 11;
int a[MAXN], b[MAXN], n, m, first, last;
ll sum;
bool C(ll mid) {
  ll tot = sum;
  memcpy(a, b, (n + 2) * sizeof(int));
  ll cur, used = 0, pos = last;
  while (tot > 0 && pos >= first) {
    used++;
    cur = mid - pos;
    while (cur > 0 && pos >= first) {
      if (used > m) return 0;
      if (cur >= a[pos]) {
        tot -= a[pos];
        cur -= a[pos];
        a[pos] = 0;
        while (pos >= first && a[pos] == 0) {
          --pos;
        }
      } else {
        a[pos] -= cur;
        tot -= cur;
        cur = 0;
      }
    }
  }
  return used <= m;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    sum = 0, last = n, first = 1;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      b[i] = a[i];
      sum += a[i];
      if (a[i]) last = i;
    }
    for (int i = n; i; --i)
      if (a[i]) first = i;
    ll lo = last + 1, hi = LONG_LONG_MAX;
    while (lo < hi) {
      ll mid = lo + (hi - lo) / 2;
      if (C(mid))
        hi = mid;
      else
        lo = mid + 1;
    }
    printf("%lld\n", lo);
  }
  return 0;
}
