#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn], m, n, mpos = 0;
vector<int> pos;
long long sum = 0;
bool ok(long long t) {
  int ss = pos.size();
  long long kk = 0;
  if (t <= pos[ss - 1]) return false;
  for (int i = 0; i < ss; i++) a[pos[i]] = b[pos[i]];
  for (int i = 0; i < n; i++) {
    long long tmp = t;
    if (!ss || kk == sum) return true;
    tmp -= pos[ss - 1];
    while (tmp > 0 && ss && kk < sum)
      if (a[pos[ss - 1]] <= tmp) {
        tmp -= a[pos[ss - 1]];
        kk += a[pos[ss - 1]];
        ss--;
      } else {
        a[pos[ss - 1]] -= tmp;
        kk += tmp;
        break;
      }
  }
  if (!ss || kk == sum) return true;
  return false;
}
int main() {
  int i, j, k;
  scanf("%d%d", &m, &n);
  pos.clear();
  for (i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
    sum += b[i];
    if (b[i] > 0) pos.push_back(i);
  }
  long long l = 0, r = 1e18;
  if (sum == 0) {
    puts("0");
    return 0;
  }
  while (l < r) {
    long long m = l + (r - l) / 2;
    if (ok(m))
      r = m;
    else
      l = m + 1;
  }
  printf("%I64d", l);
  return 0;
}
