w[100000],n,k,wgh,cnt,i,j;
cntp(int p)
{
	cnt++;
	for(j=0;j<n;)
	{
		if(wgh+w[j]<=p)wgh+=w[j++];
		else
		{
			if(wgh>0)cnt++;
			else return k+1; 
			wgh=0;
		}
	}
	return cnt;
}
l,r=1e9,m;
main()
{
	scanf("%d%d",&n,&k);
	for(;i<n;scanf("%d",w+i++));
	while(l<r)
	{
		m=(l+r)/2;
		if(cntp(m)>k)l=m+1;
		else r=m;
	}
	for(m--;;)
	{
		if(cntp(m++)<=k)break;
	}
	printf("%d\n",m);
	return 0;
}