#include <bits/stdc++.h>
using namespace std;
int box[100009];
int tmp[100009];
int n, m;
int t = 0;
bool check(long long time) {
  int k = m;
  long long s = 0;
  for (int i = 0; i < t; i++) {
    s += box[i];
    while (s + i + 1 >= time) {
      s -= time - i - 1;
      if (--k < 0) return 0;
    }
  }
  if (k == 0) return s <= 0;
  return 1;
}
int main() {
  long long l = 1, r = 100000000000000LL;
  long long mid = 0;
  long long sum = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &box[i]);
    sum += box[i];
    if (box[i]) t = i + 1;
  }
  l = t + 1;
  r = t + sum;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", r + 1);
}
