#include <bits/stdc++.h>
using namespace std;
int MX = 1e5 + 5, I = 1e9 + 9;
long long e = 1LL * I * MX + MX;
int a[100005];
int b[100005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long l = 1, r = e, mid = 0;
  while (l < r) {
    for (int i = 0; i < n; i++) b[i] = a[i];
    mid = (l + r) >> 1LL;
    int p = n - 1;
    for (int i = 0; i < m; i++) {
      while (p >= 0 && a[p] == 0) p--;
      long long rem = mid - p - 1;
      if (rem <= 0) break;
      while (rem >= b[p] && p >= 0) rem -= b[p--];
      if (p >= 0) b[p] -= rem;
      if (p < 0) break;
    }
    if (p < 0)
      r = mid;
    else
      l = mid + 1;
  }
  cout << r << endl;
  return 0;
}
