#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<long long, long long> > v, temp;
int n, m;
int arr[100005];
bool valid(long long x) {
  int idx = 0, udahakir = 0;
  ;
  int sz = temp.size();
  for (int i = 1; i <= m; i++) {
    long long cnt = 0;
    bool awal = 1;
    for (int j = idx; j < sz; j++) {
      if (awal)
        cnt = temp[j].second;
      else
        cnt += (temp[j].second - temp[j - 1].second);
      awal = false;
      if (cnt > x) {
        idx = j;
        break;
      } else if (cnt + temp[j].first > x) {
        temp[j].first -= (x - cnt);
        idx = j;
        break;
      } else {
        cnt += temp[j].first;
        temp[j].first = 0;
      }
    }
    if (temp.back().first == 0) {
      return true;
    }
  }
  return false;
}
void reset() {
  int sz = v.size();
  temp.clear();
  for (int i = 0; i < sz; i++) temp.push_back(v[i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  int PREV = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] != 0) {
      v.push_back({arr[i], i});
      PREV = i;
    }
  }
  long long ki = 0, ka = 1e14 + 1e5;
  long long pos = 0;
  while (ki <= ka) {
    long long mid = (ki + ka) / 2;
    reset();
    if (valid(mid)) {
      pos = mid;
      ka = mid - 1;
    } else
      ki = mid + 1;
  }
  cout << pos << endl;
}
