#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<long long> vals(n);
  for (int i = 0; i < n; i++) cin >> vals[i];
  function<bool(long long)> can = [&](long long x) -> bool {
    long long pplLeft = m;
    long long left = 0;
    for (int i = 0; i < n; i++) {
      long long dist = i + 1;
      long long boxes = vals[i];
      left--;
      if (left > 0) {
        long long takeLeft = min(left, boxes);
        boxes -= takeLeft;
        left -= takeLeft;
      }
      if (boxes > 0) {
        long long remainTime = x - dist;
        if (remainTime <= 0) return false;
        long long pplNeed = (boxes + remainTime - 1) / remainTime;
        pplLeft -= pplNeed;
        if (pplLeft < 0) return false;
        left = pplNeed * remainTime - boxes;
      }
    }
    return true;
  };
  long long low = 0, high = 1e15;
  while (low < high) {
    long long mid = (low + high) >> 1;
    if (can(mid))
      high = mid;
    else
      low = mid + 1;
  }
  cout << low;
}
