#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
bool check(std::vector<long long int> a, long long int n, long long int m,
           long long int t) {
  long long int i, j, t1 = t, f = 0;
  for (i = n - 1; i > -1; i--) {
    while (a[i]) {
      if (t1 <= 0) {
        if (m == 0) break;
        t1 = t;
        f = 0;
      }
      if (!f) {
        f = 1;
        t1 -= i + 1;
        m--;
      }
      long long int x = min(t1, a[i]);
      t1 -= x;
      a[i] -= x;
    }
  }
  f = 1;
  for (i = 0; i < n; i++)
    if (a[i]) f = 0;
  return f;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    long long int n, m, i, j;
    cin >> n >> m;
    std::vector<long long int> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    long long int l = 0, r = 1e18, ans;
    while (l <= r) {
      long long int mid = (l + r) / 2;
      if (check(a, n, m, mid)) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << ans;
  }
  cerr << "Time Taken:" << (float)clock() / CLOCKS_PER_SEC * 1000 << "ms"
       << "\n";
  return 0;
}
