#include <bits/stdc++.h>
using namespace std;
int n, m, ri;
vector<int> v, t;
bool possible(long long k) {
  t = v;
  int left = 0;
  for (int i = 0; i < m; i++) {
    long long time = k;
    bool first = true;
    for (int j = left; j < ri && time > 0; j++) {
      if (t[j] && first)
        time -= (j + 1);
      else
        time--;
      if (t[j]) {
        left = j;
        if (time >= t[j]) {
          time -= t[j];
          t[j] = 0;
        } else {
          t[j] -= time;
          time = 0;
        }
      }
      first = false;
    }
  }
  for (int i = 0; i < n; i++)
    if (t[i]) return false;
  return true;
}
int main() {
  int x;
  cin >> n >> m;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    if (x) ri = i + 1;
    v.push_back(x);
  }
  long long l = 0, r = n + sum, s;
  while (l < r) {
    s = (l + r) / 2;
    if (!possible(s))
      l = s + 1;
    else
      r = s;
  }
  if (possible(l))
    cout << l << endl;
  else
    cout << r << endl;
  return 0;
}
