#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], b[100005];
bool foo(long long t) {
  for (int i = 0; i < n; i++) b[i] = a[i];
  int j;
  for (j = n - 1; j >= 0; j--) {
    if (b[j]) break;
  }
  long long temp = t;
  for (int i = 0; i < m && j > -1; i++) {
    t = temp;
    t -= (j + 1);
    while (t > 0 && j > -1) {
      if (b[j] > t)
        b[j] -= t, t = 0;
      else {
        t -= b[j], b[j] = 0, j--;
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (b[i]) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long lower_bound = 1, upper_bound = 1e18;
  while (upper_bound >= lower_bound) {
    long long mid = lower_bound + (upper_bound - lower_bound) / 2;
    if (foo(mid))
      upper_bound = mid - 1;
    else
      lower_bound = mid + 1;
  }
  cout << lower_bound << "\n";
  return 0;
}
