#include <bits/stdc++.h>
using namespace std;
int n, m, tot;
long long ans, l, r, sum;
long long a[100010];
int check(long long x, long long y) {
  long long s = 0;
  for (int i = 1; i <= tot; i++) {
    s += a[i];
    while (s + i >= x) {
      s -= x - i;
      y--;
      if (y < 0) return 0;
    }
  }
  if (y == 0) return s <= 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
    if (a[i]) tot = i;
  }
  l = tot, r = tot + sum;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid, m)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld", ans);
  return 0;
}
