#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[200010];
bool check(int wide){
int tot=1,cnt=0;
while(1){
int sum=0;
while(sum<=wide){
if(sum==0){
sum+=a[tot];
}
else sum+=a[tot]+1;
tot++;
if(tot==n+1) return true;
}
sum-=a[tot--];
if(tot==n) return true;
}
return false;
}
int solve(){
int l=1,r=1e18;
while(l+1<r){
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid;
}
if(check(l)) return l;
return r;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
cout<<solve();
return 0;
}
非常显眼的二分但是没调出来,样例 2 都没过qwq