#include <bits/stdc++.h>
using namespace std;
long long int piles[100005] = {0};
long long int pilesCopy[100005] = {0};
long long int n, m;
bool check(long long int time) {
  long long int ppl = m;
  for (int i = 0; i < n; i++) {
    pilesCopy[i] = piles[i];
  }
  int last = n - 1;
  while (pilesCopy[last] == 0 && last >= 0) last--;
  while (ppl--) {
    long long int t = time;
    while (pilesCopy[last] == 0 && last >= 0) last--;
    if (last < 0) break;
    t -= (last + 1);
    if (t <= 0) break;
    while (t >= pilesCopy[last] && last >= 0) t -= pilesCopy[last--];
    if (last >= 0) pilesCopy[last] -= t;
  }
  if (last < 0)
    return true;
  else
    return false;
}
int main() {
  cin >> n >> m;
  long long int s = 0;
  for (int i = 0; i < n; i++) {
    cin >> piles[i];
    s += piles[i];
  }
  long long int l = 2;
  long long int r = n + s;
  while (l < r) {
    long long int mid = (l + r) / 2;
    bool canDo = check(mid);
    if (canDo) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
}
