#include <bits/stdc++.h>
using namespace std;
long long N, M;
long long A[100005], B[100005];
int solve(long long T) {
  int k = 1;
  for (int i = 1; i <= N; i++) B[i] = A[i];
  for (int i = 0; i < M; i++) {
    long long x = T;
    while (k <= N && B[k] == 0) k++;
    if (k > N) return 1;
    x -= k;
    while (k <= N) {
      if (k == N) {
        if (B[k] <= x) return 1;
      }
      if (x >= B[k]) {
        x -= B[k];
        B[k] = 0;
        k++;
        x--;
        while (B[k] == 0) {
          k++;
          x--;
        }
        if (k > N) return 1;
        if (x <= 0) break;
      } else {
        if (x >= 0) B[k] -= x;
        break;
      }
    }
  }
  return 0;
}
int main() {
  scanf("%lld %lld", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%lld", &A[i]);
  long long left = 0, right = N * 2000000000LL, mid;
  while (left <= right) {
    mid = (left + right) / 2;
    if (solve(mid)) {
      if (left == mid) break;
      right = mid;
    } else
      left = mid + 1;
  }
  printf("%lld\n", mid);
  return 0;
}
