#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 10, INF = 1e18;
int T, c;
long long int n, m, a[N];
bool is_possible(long long int days) {
  vector<long long int> _a(a, a + n);
  int r = n - 1;
  for (int boy = 1; boy <= m; boy++) {
    while (r >= 0 && _a[r] == 0) r--;
    if (r < 0) break;
    long long int his_days = days - r - 1;
    while (r >= 0 && _a[r] <= his_days) his_days -= _a[r--];
    if (r >= 0) _a[r] -= his_days;
  }
  if (r < 0) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int low_days = 0, high_days = accumulate(a, a + n, n);
  while (high_days - low_days > 1) {
    long long int mid = (high_days + low_days) / 2;
    if (is_possible(mid)) {
      high_days = mid;
    } else
      low_days = mid;
  }
  cout << high_days;
}
