#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long n, m, a[maxn], ed;
bool test_ok(long long time) {
  long long acc = 0;
  long long p = 0;
  for (long long i = 1; i <= ed; i++) {
    acc += a[i];
    while (i + acc >= time) {
      if (i >= time) return 0;
      acc -= (time - i);
      p++;
    }
  }
  if (p < m)
    return 1;
  else if (p == m && acc == 0)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
    if (a[i] != 0) ed = i;
  }
  long long left = 1, right = ed + sum, mid;
  while (right - left > 1) {
    mid = (left + right) / 2;
    if (test_ok(mid))
      right = mid;
    else
      left = mid;
  }
  printf("%lld\n", right);
}
