#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& __m, const T& __s) {
  if (!1) cerr << "\E[91m" << __s << "\E[0m";
  return __m;
}
C_ merr;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    merr << "Execution time: " << (double)clock() / CLOCKS_PER_SEC << " s.\n";
  }
} __S;
long long A[111111];
long long B[111111];
int main(void) {
  int n, m;
  long long sum = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    sum += A[i];
  }
  long long ll = 0, rr = 10000000000000000LL;
  while (ll < rr) {
    long long mm = (ll + rr) / 2;
    for (int i = 0; i < n; i++) {
      B[i] = 0;
    }
    int idx = n - 1;
    long long ssum = sum;
    for (int i = 0; i < m; i++) {
      idx++;
      while (idx > 0 && A[idx] - B[idx] == 0) idx--;
      long long left = mm - idx - 1;
      while (left > 0 && ssum > 0) {
        long long can = min(left, A[idx] - B[idx]);
        B[idx] += can;
        ssum -= can;
        left -= can;
        idx--;
      }
    }
    if (ssum == 0) {
      rr = mm;
    } else {
      ll = mm + 1;
    }
  }
  cout << ll << '\n';
  return 0;
}
