#include <bits/stdc++.h>
using namespace std;
vector<long long> arr;
int n, m;
bool check(long long t) {
  long long ti = t - 1, st = 1;
  vector<long long> arr1;
  arr1 = arr;
  for (int i = 1; i <= n; i++) {
    if (ti == 0) {
      st++;
      if (st > m) break;
      ti = t - i;
      if (ti <= 0) break;
      i--;
      continue;
    }
    if (ti - arr1[i] > 0) {
      ti -= arr1[i] + 1;
      arr1[i] = 0;
      continue;
    }
    if (arr1[i] > ti) {
      arr1[i] -= ti;
      ti = 0;
      i--;
      continue;
    }
    if (arr1[i] == ti) {
      arr1[i] = ti = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (arr1[i]) return 0;
  }
  return 1;
}
long long bs(long long low, long long high) {
  long long mid = (low + high) / 2;
  if (check(mid) && !check(mid - 1)) return mid;
  if (check(mid)) return bs(low, mid - 1);
  return bs(mid + 1, high);
}
int main() {
  while (cin >> n >> m) {
    arr.resize(n + 1);
    for (int i = 1; i <= n; i++) cin >> arr[i];
    cout << bs(2, 1e18) << endl;
  }
}
