#include <stdio.h>
#include <string.h>
#include <math.h>
int a[100010],l,r,n,m;
int check(int mon)
{
int i=1,j,s;
for(j=0,s=0;j<=n-1;j++)
if((s+a[j])<=mon)
s+=a[j];
else
{
s=a[j];
i++;
}
if(i<=m)
return 1;
return 0;
}
int binary_search()
{
int mid;
while(l<r)
{
mid=(l+r)/2;
if(!check(mid))
l=mid+1;
else
r=mid-1;
}
return l;
}
int main()
{
int i,t;
while(scanf("%d %d",&n,&m)!=EOF)
{
for(i=0,r=0,l=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
if(a[i]>l)
l=a[i];
r+=a[i];
}
t=binary_search();
printf("%d\n",t);
}
return 0;
}