//Time 297ms, Memory 640K
#include<iostream>
using namespace std;
int n,m;
int money[100010];
int judge(int mid)
{
int i,s=0,group=1;
for(i=0;i<n;i++)
{
if(s+money[i]<=mid)
s+=money[i];
else
{
s=money[i];group++;
}
if(group>m) return 0;
}
return 1;
}
int main()
{
int i,max,min,mid;
while(cin>>n>>m)
{
max=min=0;
for(i=0;i<n;i++)
{
cin>>money[i];
max+=money[i];
if(min<money[i])
min=money[i];
}
mid=(max+min)/2;
while(min<max)
{
if(!judge(mid))
min=mid+1;
else
max=mid-1;
mid=(max+min)/2;
}
cout<<mid<<endl;
}
}