#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
int A[N], B[N];
bool isValid(long long int x) {
  int idx = 1;
  while (!A[idx] && idx <= n) idx++;
  if (idx == n + 1) return true;
  for (int i = 1; i < n + 1; i++) B[i] = A[i];
  for (int i = 1; i < m + 1; i++) {
    long long int tmp = x;
    tmp -= idx;
    if (tmp <= 0) continue;
    while (B[idx] <= tmp && tmp > 0) {
      tmp -= B[idx];
      B[idx] = 0;
      idx++;
      if (idx == n + 1) return true;
      tmp--;
    }
    if (idx == n + 1) return true;
    if (tmp > 0) {
      B[idx] -= tmp;
      if (B[idx] < 0) B[idx] = 0;
    }
    while (!B[idx] && idx <= n) idx++;
    if (idx == n + 1) return true;
  }
  if (idx == n + 1) return true;
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n + 1; i++) scanf("%d", &A[i]);
  A[n + 1] = 1;
  long long int lo = 0, hi = 10000000000000000LL;
  long long int ans = -1;
  while (lo <= hi) {
    long long int mi = (lo + hi) >> 1;
    if (isValid(mi)) {
      ans = mi;
      hi = mi - 1;
    } else {
      lo = mi + 1;
    }
  }
  cout << ans << "\n";
  return 0;
}
