#include <fstream>
using namespace std;
ifstream in("transport.in");
ofstream out("transport.out");
const int nmax = 16000;
int n, k, a[nmax + 2], sum, maxi;
int check(int capacity){
int noww = 0, paths = 1;
for(int i = 1; i <= n; i++){
if(noww + a[i] <= capacity){
noww += a[i];
}else{ paths++; noww = a[i]; }
}
return paths;
}
int main(){
in>>n>>k;
for(int i = 1; i <= n; i++){
in>>a[i], sum += a[i];
maxi = max(maxi, a[i]);
}
int st = maxi, dr = sum + 1, mij, pos = -1;
for(; st <= dr; ){
mij = (st + dr) >> 1;
if(check(mij) <= k){
dr = mij - 1; pos = mij;
}else{ st = mij + 1; }
}
out<<pos<<"\n";
return 0;
}