#include<bits/stdc++.h>
using namespace std;
int a[100005],N,M,L,R,mid;
bool check(int x){
int sum=0,cnt=0;
for(int i=0;i<N;i++){
if(sum+a[i]<=x) sum+=a[i];
else sum=a[i],cnt++;
}
return cnt>=M;
}
int main(){
cin>>N>>M;
for(int i=0;i<N;i++){
cin>>a[i];
L=max(L,a[i]);
R=R+a[i];
}
while(L+1<R){
mid=(L+R+1)/2;
if(check(mid)) L=mid;
else R=mid;
}
cout<<L+1;
return 0;
}