#include <bits/stdc++.h>
using namespace std;
int boxs[100005];
int piles, totBox, studLen;
int check(long long x) {
  int cnt = studLen;
  int i;
  long long s = 0;
  for (i = 1; i <= totBox; i++) {
    s += boxs[i];
    while (s + i >= x) {
      s -= x - i;
      cnt--;
      if (cnt < 0) return 0;
    }
  }
  if (cnt == 0) return s <= 0;
  return 1;
}
int main() {
  long long sum, l, r, mid, ans;
  while (cin >> piles >> studLen) {
    sum = 0;
    for (int i = 1; i <= piles; i++) {
      cin >> boxs[i];
      sum += boxs[i];
      if (boxs[i]) totBox = i;
    }
    l = totBox;
    r = sum + totBox;
    while (l <= r) {
      mid = (l + r) / 2;
      if (check(mid)) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << ans << endl;
  }
  return 0;
}
