#include <bits/stdc++.h>
using namespace std;
long long a[100005], sum;
struct pile {
  long long loc, cnt;
} b[100005], c[100005];
int tot = 0;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long sum = 0, ma = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
    if (a[i]) {
      ma = i;
      b[++tot].loc = i;
      b[tot].cnt = a[i];
    }
  }
  long long l = ma, r = sum + ma;
  while (l < r) {
    long long t = (l + r) >> 1;
    int now = 1;
    for (int i = 1; i <= tot; i++) c[i] = b[i];
    for (int i = 1; i <= m; i++) {
      long long la = t - c[now - 1].loc;
      while (la > 0 && now <= tot) {
        la += c[now - 1].loc;
        la -= c[now].loc;
        long long p = min(la, c[now].cnt);
        c[now].cnt -= p;
        la -= p;
        if (!c[now].cnt) now++;
      }
    }
    if (now > tot)
      r = t;
    else
      l = t + 1;
  }
  printf("%I64d\n", l);
  return 0;
}
