#include <bits/stdc++.h>
using namespace std;
ifstream f("cf.in");
vector<long long> v, a;
long long n, m, x;
bool sol(long long t) {
  a = v;
  long long indx, sum, last_cleared = 0;
  for (long long i = 0; i < m; ++i) {
    sum = 1 + last_cleared;
    indx = last_cleared;
    while (sum < t && indx < n) {
      if (a[indx] > 0) {
        long long y = min(t - sum, a[indx]);
        sum += y, a[indx] -= y;
      } else {
        last_cleared = indx;
        ++indx, ++sum;
      }
    }
    if (sum == n && indx == n - 1) break;
  }
  for (auto x : a)
    if (x) return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) cin >> x, v.push_back(x);
  long long tmax = n + 2;
  for (auto x : v) tmax += x;
  long long l = 0, r = tmax, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (sol(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;
  return 0;
}
