#include <bits/stdc++.h>
long long a[500000], ca[500000];
long long timem;
int n, m;
bool check(long long time) {
  for (int i = 0; i < n; i++) ca[i] = a[i];
  long long st = timem;
  long long qtp = m;
  while (st >= 0 && qtp--) {
    long long fp = time - st - 1;
    while (st >= 0 && fp >= ca[st]) fp -= ca[st--];
    if (st >= 0) ca[st] -= fp;
  }
  return st < 0;
}
int main() {
  int i;
  long long x, s = 0;
  scanf("%d %d", &n, &m);
  timem = 0;
  for (i = 0; i < n; i++) {
    scanf("%lli", &a[i]);
    if (a[i]) timem = i;
    s += a[i];
  }
  long long l = timem;
  long long t = s + n;
  while (l < t) {
    x = (l + t) >> 1;
    if (check(x)) {
      t = x;
    } else {
      l = x + 1;
    }
  }
  printf("%lli\n", t);
  return 0;
}
