#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[100010], sum = 0;
void setup() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
}
bool can(long long t) {
  vector<long long> b(a, a + n + 1);
  long long s = sum;
  int p = n;
  for (int i = 1; i <= m; i++) {
    while (p && b[p] == 0) p--;
    long long tl = t - p;
    while (tl > 0 && p) {
      if (b[p] >= tl) {
        b[p] -= tl;
        s -= tl;
        break;
      }
      tl -= b[p];
      s -= b[p];
      b[p] = 0;
      p--;
    }
  }
  return (s <= 0);
}
void xuly() {
  long long l = 1, r = sum + n;
  while (r - l > 1) {
    long long g = (r + l) >> 1;
    if (can(g))
      r = g;
    else
      l = g;
  }
  cout << r;
}
int main() {
  ios_base::sync_with_stdio(0);
  setup();
  xuly();
  return 0;
}
