#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int nmax = (int)1e5 + 10;
long long n, m, a[nmax], sum = 0;
bool f(long long t) {
  long long _time;
  long long students = m;
  bool isHeNew = true;
  long long boxes = sum;
  for (int i = (int)n - 1; i >= (int)0; i--) {
    long long box = a[i];
    while (box > 0) {
      if (isHeNew) _time = t - (i + 1);
      if (box >= _time) {
        box -= _time;
        boxes -= _time;
        --students;
        if (students == 0 && boxes > 0) return false;
        isHeNew = true;
      } else {
        _time -= box;
        boxes -= box;
        box = 0;
        isHeNew = false;
      }
    }
  }
  if (boxes > 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = (int)0; i <= (int)n - 1; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long lo = 0;
  long long hi = (long long)1e15;
  while (lo < hi) {
    long long mid = (lo + hi) / 2;
    bool ok = f(mid);
    if (ok) {
      hi = mid;
    } else
      lo = mid + 1;
  }
  cout << lo << endl;
  return 0;
}
