program bly(input,output);
var
data:array[1..10000] of longint;
i,j,im,jm:longint;
p:boolean;
n,m:longint;
f1,f2:text;
function pd(money:longint):boolean;
var
z,t:integer;
begin
z:=0; t:=1;
for i:=1 to n do begin
if z+data[i]<money then z:=z+data[i]
else begin
z:=data[i];
inc(t);
end;
end;
if t<=m then pd:=true;
if t>m then pd:=false;
end;
begin
assign(f1,'expense.in');
reset(f1);
readln(f1,n,m);
for i:=1 to n do readln(f1,data[i]);
close(f1);
im:=10000;
jm:=1;
repeat
if pd((im+jm) div 2)=false then jm:=(im+jm) div 2
else im:=(im+jm) div 2;
until (im=jm)or(im=jm+1);
assign(f2,'expense.out');
rewrite(f2);
writeln(f2,(jm+im) div 2);
close(f2);
end.