#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10, inf = 0x3f3f3f3f;
int n, m;
int a[M];
int b[M];
bool judge(long long x) {
  for (int i = 1; i <= n; i++) b[i] = a[i];
  long long tmp = x;
  long long cnt = 0;
  for (int i = n; i >= 1; i--) {
    while (b[i]) {
      if (i > x) return false;
      if (tmp == x) tmp -= i, cnt++;
      if (cnt > m) return false;
      if (tmp > b[i]) {
        tmp -= b[i];
        b[i] = 0;
      } else {
        b[i] -= tmp;
        tmp = x;
      }
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long l = 1, r = (long long)1e16;
  long long ret = r;
  while (l <= r) {
    long long mid = l + r >> 1;
    if (judge(mid)) {
      r = mid - 1;
      ret = mid;
    } else
      l = mid + 1;
  }
  cout << ret << endl;
  return 0;
}
