#include <bits/stdc++.h>
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
using namespace std;
const int maxn = 1e5 + 4;
int a[maxn], temp[maxn];
long long mx[maxn];
int main(int argc, char const *argv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  ;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  ;
  long long l = 0, r = 1e15, mid;
  while (l < r - 1) {
    mid = (l + r) / 2;
    for (int i = 0; i < m; i++) mx[i] = mid;
    for (int i = 0; i < n; i++) temp[i] = a[i];
    int s = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
      if (!temp[i]) continue;
      if (s >= m) {
        flag = true;
        break;
      }
      if (temp[i] + (i + 1) == mx[s]) {
        s++;
      } else if (temp[i] + (i + 1) < mx[s]) {
        mx[s] -= temp[i];
      } else {
        temp[i] -= mx[s] - (i + 1);
        i--;
        s++;
      }
    }
    if (flag)
      l = mid;
    else
      r = mid;
  }
  printf("%I64d\n", r);
  return 0;
}
