#include <bits/stdc++.h>
using namespace std;
long long unsigned int n_pile;
long long unsigned int n_student;
bool yee(long long unsigned int pile[], long long unsigned int time) {
  long long unsigned int need_student = 0;
  long long unsigned int more_act = 0;
  for (int i = n_pile - 1; i >= 0; i--) {
    if (more_act >= pile[i]) {
      more_act -= pile[i];
      continue;
    }
    long long unsigned int temp = pile[i] - more_act;
    more_act = 0;
    if (temp > time - i - 1) {
      need_student += temp / (time - i - 1);
      temp %= (time - i - 1);
    }
    if (temp != 0) {
      need_student++;
      more_act = time - i - 1 - temp;
    }
    if (need_student > n_student) return false;
  }
  return true;
}
int main() {
  cin >> n_pile >> n_student;
  long long unsigned int pile[n_pile + 1];
  long long unsigned int n_box = 0;
  for (int i = 0; i < n_pile; i++) {
    cin >> pile[i];
    n_box += pile[i];
  }
  for (int i = n_pile - 1; i > 0 && pile[i] == 0; i--) n_pile--;
  long long unsigned int start = n_pile + 1;
  long long unsigned int end = n_pile + n_box;
  while (start != end)
    if (yee(pile, (start + end) / 2))
      end = (start + end) / 2;
    else
      start = (start + end) / 2 + 1;
  cout << start;
}
