program expense;
var
money:array [1..100000] of integer;
a,b,tmp:int64;
i,n,m:longint;
function check(num:int64):boolean;
var
k,i:longint;
sum:int64;
begin
sum:=0;k:=m;
for i:=1 to n do begin
sum:=sum+money[i];
if sum>num then begin
dec(k);
sum:=money[i];
if sum>num then exit(false);
end;
end;
dec(k);
if k<0 then exit (false) else exit (true);
end;
begin
assign (input,'expense.in');
reset (input);
readln (n,m);b:=0;
for i:=1 to n do begin
readln (money[i]);
b:=b+money[i];
end;
close (input);
assign (output,'expense.out');
rewrite (output);
a:=1;
while a<b do begin
tmp:=(a+b) div 2;
if check(tmp) then b:=tmp else a:=tmp+1;
end;
writeln (a);
close (output);
end.