#include <bits/stdc++.h>
long long n, m;
long long cnt = 0, sum = 0, ans = 0;
long long a[100010];
void prework() {
  cnt = 0, sum = 0, ans = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
    if (a[i] > 0) cnt = i;
  }
}
bool jug(long long x) {
  long long s = 0;
  long long res = m;
  for (long long i = cnt; i >= 1; i--) {
    s -= a[i];
    while (s < 0) {
      s += x - i;
      res--;
      if (res < 0) return false;
    }
  }
  if (res == 0) return s >= 0;
  return true;
}
void mainwork() {
  long long mid, l = cnt, r = cnt + sum;
  while (l + 1 < r) {
    mid = (l + r) >> 1;
    if (jug(mid))
      r = mid;
    else
      l = mid;
  }
  if (jug(l))
    ans = l;
  else
    ans = l + 1;
}
void print() { printf("%I64d\n", ans); }
int main() {
  while (~scanf("%I64d%I64d", &n, &m)) {
    prework();
    mainwork();
    print();
  }
  return 0;
}
