#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll N=1e5+5;
ll a[N];
ll n,m,l,r;
bool check(int x)
{
ll cnt=1,k=x;
for(int i=1;i<=n;i++)
{
if(k>=a[i])
{
k-=a[i];
}
else
{
cnt++;
k=x-a[i];
}
}
if(cnt>m)return true;
return false;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];l=max(l,a[i]);
r+=a[i];
}
while(l+1!=r)
{
ll mid=l+r>>1;
if(check(mid))
l=mid;
else
r=mid;
}
if(check(l))
cout<<r<<endl;
else
cout<<l<<endl;
return 0;
}