#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  long long int second;
  long long int length;
};
int main() {
  long long int n, k, i, j, val;
  cin >> n >> k;
  set<long long int> myset;
  vector<long long int> a, b;
  long long int sum = 0;
  for (i = 0; i < n; i++) scanf("%lld", &val), a.push_back(val), sum += a[i];
  long long int low = 0, high = sum + n;
  long long int mid;
  while (low <= high) {
    mid = (low + high) / 2;
    b = a;
    long long int z = mid;
    j = n - 1;
    for (i = 0; i < k && j >= 0; i++) {
      z = mid;
      while (j >= 0 && b[j] == 0) j--;
      if (j < 0) break;
      z -= (j + 1);
      if (z < 0) break;
      for (; j >= 0; j--) {
        if (z - b[j] >= 0)
          z -= b[j], b[j] = 0;
        else {
          b[j] -= z;
          break;
        }
      }
    }
    if (j < 0)
      high = mid - 1;
    else
      low = mid + 1;
  }
  cout << high + 1 << endl;
  return 0;
}
