#include <bits/stdc++.h>
using namespace std;
int debug = 1;
const int LIM = 1e5 + 3;
long long int T, n, i, j, k, p, q, l, r, m, x, y, z;
long long int A[LIM];
long long int B[LIM];
long long int solve(long long int x) {
  long long int total = 0;
  for (i = 1; i <= n; i++) {
    total += A[i] + 1;
    B[i] = A[i];
  }
  if (total <= x) return true;
  long long int left = x, cnt = 0;
  for (i = n; i > 0;) {
    if (!B[i]) {
      i--;
      continue;
    }
    if (cnt == m) return 0;
    if (left == x) left -= i;
    if (left <= 0) return 0;
    p = min(left, B[i]);
    B[i] = B[i] - p;
    left = left - p;
    if (!left) {
      cnt++;
      left = x;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (i = 1; i < n + 1; i++) cin >> A[i];
  long long int low = 1, high = 0x7f7f7f7f * 1LL * 0x7f7f7f7f, mid;
  for (long long int it = 1; it <= 200; it++) {
    mid = (low + high) / 2;
    if (solve(mid))
      high = mid;
    else
      low = mid + 1;
  }
  cout << mid << "\n";
  return 0;
}
