#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int n, m;
bool can(long long tt) {
  if (tt == 4) tt += 0;
  vector<int> v = a;
  int k = n - 1;
  for (int i = 0; i < m; i++) {
    long long t = tt;
    while (k > 0 && v[k] == 0) k--;
    if (k == -1) return 1;
    t -= k + 1;
    if (t < 0) return 0;
    while (t > 0 && k >= 0) {
      if (t >= v[k]) {
        t -= v[k];
        v[k] = 0;
        k--;
      } else {
        v[k] -= t;
        t = 0;
      }
    }
  }
  while (k > 0 && v[k] == 0) k--;
  return k == -1 || v[k] == 0;
}
int main() {
  cin >> n >> m;
  a = vector<int>(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  long long l = 1, r = 100000000100010, res, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (can(mid))
      r = mid - 1, res = mid;
    else
      l = mid + 1;
  }
  cout << res;
  return 0;
}
