#include <bits/stdc++.h>
using namespace std;
long long n, m, a[100005], c[100005];
bool chk(long long t) {
  memcpy(c, a, sizeof a);
  long long pt = 1;
  for (long long i = 1; i <= m; i++) {
    long long res = t - pt;
    while (res >= c[pt] && pt <= n) res -= c[pt++] + 1;
    if (res > 0) c[pt] -= res;
  }
  return pt > n;
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  while (!a[n]) n--;
  long long lt = 1, rt = 1e15;
  while (lt <= rt) {
    long long t = lt + rt >> 1;
    if (chk(t))
      rt = t - 1;
    else
      lt = t + 1;
  }
  cout << lt << endl;
  return 0;
}
