#include <bits/stdc++.h>
using namespace std;
long long n, m, a[100005], sum, en;
bool cheak(long long mid) {
  long long sum = 0, cnt = m;
  for (int i = 1; i <= n; ++i) {
    if (a[i]) {
      sum += a[i];
      while (sum > mid - i) {
        sum -= (mid - i);
        cnt--;
        if (cnt < 0) return 0;
      }
    }
  }
  if (!cnt) return sum <= 0;
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  long long l = 0, r = 1e17, ans;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (cheak(mid))
      ans = mid, r = mid;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
