#include <bits/stdc++.h>
using namespace std;
inline long long msb(long long val) { return 63 - __builtin_clzll(val); }
inline int msb(int val) { return 31 - __builtin_clz(val); }
template <class T>
bool chmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool chmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
const long long mod = 1e9 + 7, N = 1e5 + 5;
long long a[N], b[N], n, m, k;
bool check(long long t) {
  long long now = n;
  for (long long i = 1; i <= n; i++) b[i] = a[i];
  for (; now > 0 && b[now] == 0;) now--;
  for (long long i = 0; i < m; i++) {
    long long left = t;
    for (; now > 0 && b[now] == 0;) now--;
    left -= now;
    while (now > 0 && left > 0) {
      if (b[now] == 0) {
        now--;
        continue;
      }
      if (b[now] > left)
        b[now] -= left, left = -1;
      else
        left -= b[now], b[now] = 0, now--;
    }
  }
  for (long long i = 1; i <= n; i++)
    if (b[i]) return false;
  return true;
}
void solve(long long test_case) {
  long long i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  check(2);
  long long l = 0, r = 1e16;
  while (l + 1 < r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r << '\n';
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  solve(1);
  return 0;
}
