#include <bits/stdc++.h>
using namespace std;
bool check(long long m, vector<int> v, int n, int s) {
  vector<long long> rem(s, m);
  for (int i = 1; i <= n; i++) {
    while (v[i] > 0) {
      while (rem.size() > 0 && rem.back() <= i) rem.pop_back();
      if (rem.size() == 0) return false;
      int d = (int)min((long long)v[i], rem.back() - i);
      v[i] -= d;
      rem.back() -= d;
    }
  }
  return true;
}
int main() {
  int n, s;
  scanf("%d%d", &n, &s);
  vector<int> v(n + 1);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  long long ans;
  for (long long l = 2, r = 1000000000000000LL; l < r;) {
    long long m = (l + r) / 2;
    if (check(m, v, n, s))
      ans = r = m;
    else
      l = m + 1;
  }
  printf("%I64d\n", ans);
}
