#include <iostream>
#include <cstdio>
#include <algorithm>
#define MAXN 1000050
using namespace std;
int n , m;
long long a[ MAXN ];
long long l = -9999999999 , r;
bool check( long long mid )
{
int k = 0;
long long now = 0;
for( int i = 1 ; i <= n ; i++ )
{
if( now + a[i] <= mid ) now += a[i];
else now = a[i] , k++;
}
return k >= m;
}
int main()
{
cin >> n >> m;
for( int i = 1 ; i <= n ; i++ )
{
cin >> a[i];
l = max( l , a[i] );
r += a[i];
}
long long ans = 0;
while( l <= r )
{
long long mid = ( l + r ) / 2;
if( check( mid ) ) ans = mid , l = mid + 1;
else r = mid - 1;
}
cout << l << endl;
// 这种不行:cout << ans << endl;
return 0;
}