#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int l,r,i,j,k,a=0,b,n,m;
	int t,c,d;
	cin>>n>>m;
	int *A,*B;
	A = (int *)malloc(n*sizeof(int));
	B = (int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		a+=A[i];
	}
	r = n + a;
	l = 0;
	while(l<r)
	{
		c = (l+r)/2;
		b = a;
		for(j=0;j<m;j++)
		{
			t = 1;
			for(i=0;i<n;i++)
			{
				if(j==0)
					B[i] = A[i];
				while(B[i]>0 && t<c)
				{
					d = min(B[i],c-t);
					B[i]-=d;
					b-=d;
					t+=d;
				}
				t++;
			}
			if(!b)
				break;
		}
		if(!b)
			r = c;
		else
			l = c+1;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int l,r,i,j,k,t,a=0,b,c,n,m;
	cin>>n>>m;
	int *A,*B;
	A = (int *)malloc(n*sizeof(int));
	B = (int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		a+=A[i];
	}
	r = n + a;
	l = 0;
	while(l<r)
	{
		c = (l+r)/2;
		b = a;
		for(j=0;j<m;j++)
		{
			t = 1;
			for(i=0;i<n;i++)
			{
				if(j==0)
					B[i] = A[i];
				while(B[i]>0 && t<c)
				{
					B[i]--;
					b--;
					t++;
				}
				t++;
			}
		}
		if(!b)
			r = c;
		else
			l = c+1;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int l,r,i,j,k,a=0,b,n,m,p;
	long long int t,c,d;
	cin>>n>>m;
	long long *A,*B;
	A = (long long *)malloc(n*sizeof(long long));
	B = (long long *)malloc(n*sizeof(long long));
	for(i=0;i<n;i++)
	{
		scanf("%lld",&A[i]);
		a+=A[i];
	}
	r = n + a;
	l = 0;
	while(l<r)
	{
		c = (l+r)/2;
		b = a;
		t = 1;
		j = 0;
		memset(B,-1,n*sizeof(long long));
		i = 0;
		while(i<n)
		{
			if(B[i] == -1)
				B[i] = A[i];
			if(B[i]>0 && t<c)
			{
				d = min(B[i],c-t);
				B[i] -= d;
				b -= d;
				t += d;
			}
			if(B[i]==0 && t<c)
			{
				i++;
				t++;
			}
			if(t==c && j<m)
			{
				t = i+1;
				j++;
			}
			if(b==0 || j==m)
				break;
		}
		if(!b)
			r = c;
		else
			l = c+1;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int l,r,i,j,k,t,a=0,b,c,n,m;
	cin>>n>>m;
	int *A,*B;
	A = (int *)malloc(n*sizeof(int));
	B = (int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		a+=A[i];
	}
	r = n + a;
	l = 0;
	while(l<r)
	{
		c = (l+r)/2;
		memcpy(B,A,n*sizeof(int));
		b = a;
		for(j=0;j<m;j++)
		{
			t = 1;
			for(i=0;i<n;i++)
			{
				while(B[i]>0 && t<c)
				{
					B[i]--;
					b--;
					t++;
				}
				t++;
				if(t>=c)
					break;
			}
		}
		if(!b)
			r = c;
		else
			l = c+1;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int l,r,i,j,k,a=0,b,n,m,p;
	int t,c,d;
	cin>>n>>m;
	int *A,*B;
	A = (int *)malloc(n*sizeof(int));
	B = (int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		a+=A[i];
	}
	r = n + a;
	l = 0;
	while(l<r)
	{
		c = (l+r)/2;
		b = a;
		t = 1;
		j = 0;
		memset(B,-1,n*sizeof(int));
		i = 0;
		while(i<n)
		{
			if(B[i] == -1)
				B[i] = A[i];
			if(B[i]>0 && t<c)
			{
				d = min(B[i],c-t);
				B[i] -= d;
				b -= d;
				t += d;
			}
			if(B[i]==0 && t<c)
			{
				i++;
				t++;
			}
			if(t==c && j<m)
			{
				t = i+1;
				j++;
			}
			if(b==0 || j==m)
				break;
		}
		if(!b)
			r = c;
		else
			l = c+1;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int l,r,i,j,k,a=0,b,n,m;
	int t,c,d;
	cin>>n>>m;
	int *A,*B;
	A = (int *)malloc(n*sizeof(int));
	B = (int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		a+=A[i];
	}
	r = n + a;
	l = 0;
	while(l<r)
	{
		c = (l+r)/2;
		b = a;
		for(j=0;j<m;j++)
		{
			t = 1;
			for(i=0;i<n;i++)
			{
				if(j==0)
					B[i] = A[i];
				while(B[i]>0 && t<c)
				{
					d = min(B[i],c-t);
					B[i]-=d;
					b-=d;
					t+=d;
				}
				t++;
			}
		}
		if(!b)
			r = c;
		else
			l = c+1;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int l,r,i,j,k,t,a=0,b,c,n,m;
	cin>>n>>m;
	int *A,*B;
	A = (int *)malloc(n*sizeof(int));
	B = (int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		a+=A[i];
	}
	r = n + a;
	l = 0;
	while(l<r)
	{
		c = (l+r)/2;
		memcpy(B,A,n*sizeof(int));
		b = a;
		for(j=0;j<m;j++)
		{
			t = 1;
			for(i=0;i<n;i++)
			{
				while(B[i]>0 && t<c)
				{
					B[i]--;
					b--;
					t++;
				}
				t++;
				if(t>=c)
					break;
			}
		}
		if(!b)
			r = c;
		else
			l = c+1;
	}
	cout<<r<<endl;
	return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(i,m) {
        ll tempt = t ;
        int last = -1 ;
        int lastl = n-1 ;
        int j = n-1 ;
        while (lastl>=0 && temp[j] == 0){
            lastl --;
        }
        if (tempt - lastl-1 <= 0) break ;
        lp(i,lastl+1) {
            if (temp [i] == 0 ){
                if (tempt - (i - last) <= 0 ) break;
                continue;
            }
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    int temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(j,m) {
        ll tempt = t ;
        int lastl = n-1 ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }
        if (tempt - lastl-1 <= 0) break ;
        tempt -= lastl+1;
        lp(i,lastl+1) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    int lastl = n-1 ;
    lp(j,m) {
        ll tempt = t ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }

        tempt -= lastl+1;
        if (tempt <= 0) break ;
          int i = lastl ;
         while (lastl >= 0 ) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
           lastl--;
        }

        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    int temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(j,m) {
        ll tempt = t ;
        int lastl = n-1 ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }
        if (tempt - lastl-1 <= 0) break ;
        tempt -= lastl+1;
        lp(i,lastl+1) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(i,m) {
        ll tempt = t ;
        int last = -1 ;
        int lastl = n-1 ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }
        if (tempt - lastl-1 <= 0) break ;
        lp(i,lastl+1) {
            if (temp [i] == 0 ){
                if (tempt - (i - last) <= 0 ) break;
                continue;
            }
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(i,m) {
        ll tempt = t ;
        int last = -1 ;
        int lastl = n-1 ;
        int j = n-1 ;
        while (lastl>=0 && temp[j] == 0){
            lastl --;
        }
        if (tempt <= n-lastl-1) break ;
        lp(i,lastl+1) {
            if (temp [i] == 0 ){
                if (tempt - (i - last) <= 0 ) break;
                continue;
            }
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    int temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(j,m) {
        ll tempt = t ;
        int lastl = n-1 ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }
        if (tempt - lastl-1 <= 0) break ;
        tempt -= lastl-1;
        lp(i,lastl+1) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    ll temp [n];
    lp(i,n) {
        temp [i] = a[i];
    }
    int i = n-1 ;
    lp(j,m) {
        ll tempt = t ;
        while (i>=0 && temp[i] == 0){
            i--;
        }
        tempt -= i+1;
        if (tempt <= 0) break ;
         while (i >= 0 ) {
           if (temp[i] <= tempt) {
               tempt -= temp[i];
               i--;
           } else {
              temp[i] -= tempt ;
              tempt = 0 ;
              break ;
           }
          // if (tempt <= 0 ) break;
        }
    }
    if (i>=0) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(j,m) {
        ll tempt = t ;
        int lastl = n-1 ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }
        if (tempt - lastl-1 <= 0) break ;
        tempt -= lastl+1;
        lp(i,lastl+1) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%I64d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        int lastl = -2 ;
        int i = n-1 ;
        while (i>=0 && temp[i] > 0) lastl = i , i-- ;
        lp(i,lastl+1) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        lp(i,n) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    lp(i,n) cin >> a[i];
   ll lo = 0 , hi = 1000000000000000;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    int lastl = n-1 ;
    lp(j,m) {
        ll tempt = t ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }

        tempt -= lastl+1;
        if (tempt <= 0) break ;
          int i = lastl ;
         while (lastl >= 0 ) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
           lastl--;
        }

        if (finished == sum) return true ;
    }
    if (lastl>=0) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
    int lastl = n-1 ;
    lp(j,m) {
        ll tempt = t ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }

        tempt -= lastl+1;
        if (tempt <= 0) break ;
          int i = lastl ;
         while (lastl >= 0 ) {
           if (temp[i] >= tempt) {
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              tempt -= temp[i];
              temp[i] = 0 ;
              i--;
           }
           if (tempt <= 0 ) break;
           lastl--;
        }
    }
    if (lastl>=0) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        lp(i,n) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    lp(i,n) cin >> a[i];
   ll lo = 0 , hi = 1000000000000000;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        int lastl = -2 ;
        int i = n-1 ;
        while (i>=0 && a[i] > 0) lastl = i , i-- ;
        lp(i,lastl+1) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        int lastl = n-1 ;
        int i = n-1 ;
        while (lastl>=0 && temp[i] == 0){
            lastl --;
        }
        if (tempt <= n-lastl-1) break ;
        lp(i,lastl+1) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        int lastl = n-1 ;
        int i = n-1 ;
        while (lastl>=0 && temp[i] == 0){
            lastl --;
        }
        lp(i,lastl+1) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        lp(i,n) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    lp(i,n) cin >> a[i];
   ll lo = 0 , hi = 1000000000000000;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(j,m) {
        ll tempt = t ;
        int lastl = n-1 ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }

        tempt -= lastl+1;
        if (tempt <= 0) break ;
          int i = lastl ;
         while (lastl >= 0 ) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
           lastl--;
        }

        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
int a[100005] ;
bool can ( ll t  ) {
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    lp(j,m) {
        ll tempt = t ;
        int lastl = n-1 ;
        while (lastl>=0 && temp[lastl] == 0){
            lastl --;
        }

        tempt -= lastl+1;
        if (tempt <= 0) break ;

        lp(i,lastl+1) {
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }

        if (finished == sum) return true ;
    }
    if (finished != sum) return false ;
    return true ;

}

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        scanf("%d",&a[i]);
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << hi ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        lp(i,n) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        cin >> a[i];
        sum += a[i];

    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <iostream>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((ll)v.size())
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define pb                  push_back
#define MP                  make_pair
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<pair<double, double> > vdd;
typedef vector<pair<pair<int, int>, int> > viii;
typedef vector<pair<pair<int, int>, double> > viid;
typedef pair<pair<int, int>, int> iii;
typedef pair<pair<int, int>, double> iid;
struct edje {
    int from, to;
    ll w;
    edje(int from, int to, ll w) :
            from(from), to(to), w(w) {
    }
    bool operator <(const edje & e) const {
        return w < e.w;
    }

};
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

const ll oo = (ll) ((1e18) + 1);
const double eps = 1e-9;
const ll mod7 = 1000000007;
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}
ll strTonumModa(string s, ll athemod) {
    ll ans = 0;
    for (ll i = 0; i < sz(s); i++) {
        // from left to right
        ans = (ans * 10 + s[i] - '0') % athemod;
        // from right to left
        /* ll exp = (s[sz(s)-i -1]-'0') * mod_exp(  10 , i  );
         ans = (ans + exp) % athemod;*/
    }
    return ans;
}
ll mod_exp(ll base, ll p , ll MOD) {
    if (p == 0)
        return 1;
    if (p == 1)
        return base;
    ll ret = mod_exp(base, p / 2,MOD) % MOD;
    ret = (ret * ret) % MOD;
    if (p % 2 == 1)
        ret = (ret * base) % MOD;
    return ret;
}
string getstr(ll x) {
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
ll n , m ;
ll a[100005] ;
bool can ( ll t  ) {
    ll temo = m ;
    ll temp [n];
    ll sum = 0 ;
    lp(i,n) {
        temp [i] = a[i];
        sum += a[i];
    }
   ll finished = 0 ;
    while (temo>0) {
        ll tempt = t ;
        int last = -1 ;
        lp(i,n) {
            if (temp [i] == 0 ) continue;
            tempt -= (i - last) ;
            if (tempt <= 0 ) break;
           if (temp[i] >= tempt) {
               finished += tempt ;
               temp[i] -= tempt ;
               tempt = 0 ;
               last = i;
               break ;
           } else {
              finished += temp[i];
              tempt -= temp[i];
              temp[i] = 0 ;
              last = i;
           }
           if (tempt <= 0 ) break;
           if (finished == sum) return true ;
        }
        if (finished == sum) return true ;
        temo--;
    }
    if (finished != sum) return false ;
return true ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m ;
    ll sum = 0 ;
    lp(i,n){
        sum += a[i];
        cin >> a[i];
    }
   ll lo = 0 , hi = sum+n;
   while (lo<hi) {
       ll mid = lo + (hi-lo)/2 ;
       if (can(mid)) {
        //   cout << mid << " yes " << endl;
           hi = mid;
       }
       else {
        //   cout << mid << " no " << endl;
           lo = mid+1;
       }
   }
    cout << lo ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 5;

int n, m, a[maxn];
bool check(long long mid) {
	int cur = m; long long s = 0;
	for (int i = 1; i <= n; ++ i) {
		s += a[i];
		while (s + i >= mid) {
			s -= mid - i;
			-- cur;
			if (cur < 0) return false;
		}
	}
	if (cur == 0) return s <= 0;
	return true;
}

int main(void) {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
	}
	long long L = 0, R = 1e9, ans = -1;
	while (L <= R) {
		long long mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << ans << endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 5;

int n, m, a[maxn];
bool check(long long mid) {
	int cur = m; long long s = 0;
	for (int i = 1; i <= n; ++ i) {
		s += a[i];
		while (s + i >= mid) {
			s -= mid - i;
			-- cur;
			if (cur < 0) return false;
		}
	}
	if (cur == 0) return s <= 0;
	return true;
}

int main(void) {
	scanf("%d%d", &n, &m); int now = 0;
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]); if (a[i]) now = i;
	}
	long long L = i, R = 1e18, ans = -1;
	while (L <= R) {
		long long mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << ans << endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 5;

int n, m, a[maxn];
bool check(long long mid) {
	int cur = m; long long s = 0;
	for (int i = 1; i <= n; ++ i) {
		s += a[i];
		while (s + i >= mid) {
			s -= mid - i;
			-- cur;
			if (cur < 0) return false;
		}
	}
	if (cur == 0) return s <= 0;
	return true;
}

int main(void) {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
	}
	long long L = 0, R = 1e18, ans = -1;
	while (L <= R) {
		long long mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << ans << endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 5;

int n, m, a[maxn];
bool check(int mid) {
	int cur = m; long long s = 0;
	for (int i = 1; i <= n; ++ i) {
		s += a[i];
		while (s + i >= mid) {
			s -= mid - i;
			-- cur;
			if (cur < 0) return false;
		}
	}
	if (cur == 0) return s <= 0;
	return true;
}

int main(void) {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
	}
	int L = 0, R = 1e9, ans = -1;
	while (L <= R) {
		int mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << ans << endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 5;

int n, m;
long long a[maxn];
bool check(long long mid) {
	int cur = m; long long s = 0;
	for (int i = 1; i <= n; ++ i) {
		s += a[i];
		while (s + i >= mid) {
			s -= mid - i;
			-- cur;
			if (cur < 0) return false;
		}
	}
	if (cur == 0) return s <= 0;
	return 1;
}

int main(void) {
	scanf("%d%d", &n, &m); int now = 0; long long p = 0;
	for (int i = 1; i <= n; ++ i) {
		scanf("%lld", &a[i]); if (a[i]) now = i; p += a[i];
	}
	long long L = now, R = p + now, ans = -1;
	while (L <= R) {
		long long mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << ans << endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 5;

int n, m;
long long a[maxn];
bool check(long long mid) {
	int cur = m; long long s = 0;
	for (int i = 1; i <= n; ++ i) {
		s += a[i];
		while (s + i >= mid) {
			s -= mid - i;
			-- cur;
			if (cur < 0) return false;
		}
	}
	if (cur == 0) return s <= 0;
	return true;
}

int main(void) {
	scanf("%d%d", &n, &m); int now = 0;
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]); if (a[i]) now = i;
	}
	long long L = now, R = 1e18, ans = -1;
	while (L <= R) {
		long long mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << ans << endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 5;

int n, m;int now = 0;
long long a[maxn];

int check(long long mid) {
	int cur = m; long long s = 0;
	for (int i = 1; i <= now; ++ i) {
		s += a[i];
		while (s + i >= mid) {
			s -= mid - i;
			-- cur;
			if (cur < 0) return false;
		}
	}
	if (cur == 0) return s <= 0;
	return 1;
}

int main(void) {
	scanf("%d%d", &n, &m);  long long p = 0;
	for (int i = 1; i <= n; ++ i) {
		scanf("%lld", &a[i]); if (a[i]) now = i; p += a[i];
	}
	long long L = now, R = p + now, ans = -1;
	while (L <= R) {
		long long mid = (L + R) >> 1;
		if (check(mid)) {
			ans = mid;
			R = mid - 1;
		} else L = mid + 1;
	}
	cout << ans << endl;
	return 0;

}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <list>
#include <algorithm>
#include <climits>
using namespace std;
#define LL long long
#define N 100005

int n,m,tot;
LL a[N];

int check(LL x)
{
    int cnt = m;
    int i,j,k;
    LL s = 0;
    for(i = 1; i<=tot; i++)
    {
        s+=a[i];
        while(s+i>=x)//移动箱子加移动路程的总时间超过了x
        {
            s-=x-i;//对于已走的路程i，那么一个人有x-i个时间来搬箱子，所以每增加一人，时间消耗可以减少x-i
            cnt--;
            if(cnt<0) return 0;
        }
    }
    if(cnt==0) return s<=0;
    return 1;
}

int main()
{
    int i,j;
    LL ans,sum,l,r;
    while(~scanf("%d%d",&n,&m))
    {
        sum = 0;
        for(i = 1; i<=n; i++)
        {
            scanf("%I64d",&a[i]);
            sum+=a[i];
            if(a[i])
                tot = i;
        }
        l = tot,r = tot+sum;
        while(l<=r)
        {
            LL mid = (l+r)>>1;
            if(check(mid))
            {
                ans = mid;
                r = mid-1;
            }
            else
                l = mid+1;
        }
        printf("%I64d\n",ans);
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 100010;

long long a[MAXN];

long long judge (long long n, long long k)
{
    long long total = 0;
    for (long long i = 1; i <= n; i ++)
    {
        long long j = k;
        j -= i;
        total += a[i] / j;
        if (a[i] % j != 0) total ++;
    }
    return total;
}

int main ()
{
    long long n, m;
    scanf ("%I64d%I64d", &n, &m);
    long long total = 0, last = 0;
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%I64d", &a[i]);
        if (a[i])
        {
            if (i + 1 > last)
            {
                last = i + 1;
            }
        }
        total += 1 + a[i];
    }
    long long l = last, r = total, mid, ans = total;
    while (l <= r)
    {
        long long mid = (l + r) >> 1;
        if (judge (n, mid) <= m)
        {
            r = mid - 1;
            ans = mid;
        }
        else
        {
            l = mid + 1;
        }
    }
    printf ("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 100010;

long long a[MAXN];

long long judge (long long n, long long k)
{
    long long total = 0, tmp = 0;
    for (long long i = 1; i <= n; i ++)
    {
        long long j = k;
        j -= i;
        total += a[i] / j;
        tmp += a[i] % j;
        if (tmp + i >= k)
        {
            total += (tmp + i) / k;
            tmp = (tmp + i) % k;
        }
    }
    return total;
}

int main ()
{
    long long n, m;
    scanf ("%I64d%I64d", &n, &m);
    long long total = 0, last = 0;
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%I64d", &a[i]);
        if (a[i])
        {
            if (i + 1 > last)
            {
                last = i + 1;
            }
        }
        total += 1 + a[i];
    }
    if (!last) printf ("0\n");
    else
    {
        long long l = last, r = total, mid, ans = total;
        while (l <= r)
        {
            long long mid = (l + r) >> 1;
            if (judge (n, mid) <= m)
            {
                r = mid - 1;
                ans = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        printf ("%I64d\n", ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 100010;

long long a[MAXN];

long long judge (long long n, long long k)
{
    long long total = 0;
    for (long long i = 1; i <= n; i ++)
    {
        long long j = k;
        j -= i;
        total += a[i] / j;
        if (a[i] % j != 0) total ++;
    }
    return total;
}

int main ()
{
    long long n, m;
    scanf ("%I64d%I64d", &n, &m);
    long long total = 0, last = 0;
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%I64d", &a[i]);
        if (a[i])
        {
            if (i + 1 > last)
            {
                last = i + 1;
            }
        }
        total += 1 + a[i];
    }
    if (!last) printf ("0\n");
    else
    {
        long long l = last, r = total, mid, ans = total;
        while (l <= r)
        {
            long long mid = (l + r) >> 1;
            if (judge (n, mid) <= m)
            {
                r = mid - 1;
                ans = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        printf ("%I64d\n", ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 100010;

long long a[MAXN];

long long judge (long long n, long long k)
{
    long long total = 0, tmp = 0;
    for (long long i = 1; i <= n; i ++)
    {
        if (!a[i]) continue;
        long long j = k;
        j -= i;
        total += a[i] / j;
        tmp += a[i] % j;
        if (tmp + i >= k)
        {
            total += (tmp + i) / k;
            tmp = (tmp + i) % k;
        }
    }
    if (tmp) total ++;
    return total;
}

int main ()
{
    long long n, m;
    scanf ("%I64d%I64d", &n, &m);
    long long total = 0, last = 0;
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%I64d", &a[i]);
        if (a[i])
        {
            last = i + 1;
        }
        total += 1 + a[i];
    }
    total -= n - last;
    if (!last) printf ("0\n");
    else
    {
        long long l = last, r = total, mid, ans = total;
        while (l <= r)
        {
            long long mid = (l + r) >> 1;
            if (judge (n, mid) <= m)
            {
                r = mid - 1;
                ans = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        printf ("%I64d\n", ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 100010;

long long a[MAXN];

long long judge (long long n, long long k)
{
    long long total = 0, tmp = 0;
    for (long long i = 1; i <= n; i ++)
    {
        long long j = k;
        j -= i;
        total += a[i] / j;
        tmp += a[i] % j;
        if (tmp + i >= k)
        {
            total += (tmp + i) / k;
            tmp = (tmp + i) % k;
        }
    }
    if (tmp) total ++;
    return total;
}

int main ()
{
    long long n, m;
    scanf ("%I64d%I64d", &n, &m);
    long long total = 0, last = 0;
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%I64d", &a[i]);
        if (a[i])
        {
            if (i + 1 > last)
            {
                last = i + 1;
            }
        }
        total += 1 + a[i];
    }
    if (!last) printf ("0\n");
    else
    {
        long long l = last, r = total, mid, ans = total;
        while (l <= r)
        {
            long long mid = (l + r) >> 1;
            if (judge (n, mid) <= m)
            {
                r = mid - 1;
                ans = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        printf ("%I64d\n", ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 100010;

long long a[MAXN];

long long judge (long long n, long long k)
{
    long long total = 0, tmp = 0;
    for (long long i = 1; i <= n; i ++)
    {
        long long j = k;
        j -= i;
        total += a[i] / j;
        tmp += a[i] % j;
        if (tmp + i >= k)
        {
            total += (tmp + i) / k;
            tmp = (tmp + i) % k;
        }
    }
    if (tmp) total ++;
    return total;
}

int main ()
{
    long long n, m;
    scanf ("%I64d%I64d", &n, &m);
    long long total = 0, last = 0;
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%I64d", &a[i]);
        if (a[i])
        {
            last = i + 1;
        }
        total += 1 + a[i];
    }
    total -= n - last;
    if (!last) printf ("0\n");
    else
    {
        long long l = last, r = total, mid, ans = total;
        while (l <= r)
        {
            long long mid = (l + r) >> 1;
            if (judge (n, mid) <= m)
            {
                r = mid - 1;
                ans = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        printf ("%I64d\n", ans);
    }
    return 0;
}