#include <bits/stdc++.h>
using namespace std;
const int N = 131420;
long long a[N], temp[N];
bool Check(const long long &n, const long long &t, const long long &m) {
  memcpy(temp, a, n * sizeof(long long));
  for (int i = 0, j = 0; i < m; ++i) {
    long long p = t - j - 1;
    while (1) {
      if (j >= n) {
        return 1;
      }
      if (p <= 0) {
        break;
      }
      if (temp[j] > p) {
        temp[j] -= p;
        p = 0;
      } else {
        p -= temp[j];
        temp[j] = 0;
        ++j;
        --p;
      }
    }
  }
  return 0;
}
int main() {
  long long n, m;
  while (cin >> n >> m) {
    long long l = 0, r = n, mid, mk, t;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      r += a[i];
      if (a[i]) {
        t = i;
      }
    }
    n = t + 1;
    while (l <= r) {
      mid = l + r >> 1;
      if (Check(n, mid, m)) {
        mk = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    cout << mk << endl;
  }
  return 0;
}
