#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
long long n, m;
long long a[maxn], b[maxn];
long long sum;
bool check(long long t) {
  long long tmp = t, x = m - 1;
  for (int i = 1; i <= n; i++) b[i] = a[i];
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    if (tmp > 0)
      tmp--;
    else {
      if (x == 0) return false;
      x--;
      tmp = t - i;
    }
    if (tmp >= b[i])
      tmp -= b[i], b[i] = 0;
    else {
      b[i] -= tmp;
      if (x == 0) return false;
      x--;
      tmp = t - i;
      while (b[i] > 0) {
        if (b[i] > tmp) {
          b[i] -= tmp;
          if (x == 0) return false;
          x--;
          tmp = t - i;
        } else
          tmp -= b[i], b[i] = 0;
      }
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int p = n;
  while (a[p] == 0) {
    n--;
    p = n;
  }
  long long l = n + 1, r = 1e18;
  long long ans = n + 1;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return ~~(0 - 0);
}
