#include <bits/stdc++.h>
using namespace std;
int n, m;
long long sum;
bool isPossible(vector<int> pile, long long sec) {
  long long pileidx = n - 1;
  for (int i = 0; i < m; i++) {
    long long amount = sec;
    while (pileidx >= 0 && pile[pileidx] == 0) {
      pileidx--;
    }
    amount -= (pileidx + 1);
    while (amount) {
      if (pileidx == -1) break;
      if (pile[pileidx] <= amount) {
        amount = amount - pile[pileidx];
        pile[pileidx] = 0;
        pileidx--;
      } else {
        pile[pileidx] -= amount;
        amount = 0;
      }
    }
  }
  bool flag = true;
  for (int i = 0; i < n; i++) {
    if (pile[i] != 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
long long optimize(vector<int> pile) {
  long long lo = 0, hi = 1e15;
  while (lo < hi - 1) {
    long long mid = (lo + hi) / 2;
    if (isPossible(pile, mid))
      hi = mid;
    else
      lo = mid;
  }
  return hi;
}
int main() {
  cin >> n >> m;
  sum = 0;
  vector<int> pile;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    sum += t;
    pile.push_back(t);
  }
  cout << optimize(pile);
  return 0;
}
