#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, m, a[N], b[N];
long long l, r, c;
bool check(long long *t) {
  for (int i = 0; i < n; i++) b[i] = a[i];
  int dex = 0;
  for (int i = 0; i < m; i++) {
    long long remain = *t - dex - 1;
    while ((remain >= b[dex] || !b[dex]) && dex < n) remain -= b[dex++] + 1;
    if (dex < n) b[dex] -= max(remain, 0ll);
  }
  return (dex >= n);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  l = -1, r = 1e16;
  while (r - l > 1) {
    c = (l + r) / 2;
    check(&c) ? r = c : l = c;
  }
  cout << r;
  return 0;
}
