#include<cstdio>
const int N=100010;
int n,m,a[N];
int erfen(int l,int r){
if (l==r) return l;
int mid=(l+r)>>1,p=0,cnt=1;
for (int i=1;i<=n;i++)
if (a[i]-a[p]>mid) cnt++,p=i-1;
return cnt<=m?erfen(l,mid):erfen(mid+1,r);
}
int main()
{
freopen("expense.in","r",stdin);
freopen("expense.out","w",stdout);
scanf("%d%d",&n,&m);
int Max=0;
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
if (a[i]>Max) Max=a[i];
a[i]+=a[i-1];
}
printf("%d\n",erfen(Max,a[n]));
return 0;
}