program xmz;
var
f1,f2:text;
x:array[1..100000]of longint;
sum,a,n,m:longint;
function ok(nn:longint):boolean;
var
i,j,ss:longint;
begin
j:=1;ss:=0;
for i:=1 to n do
if ss+x[i]<=nn then inc(ss,x[i])
else begin ss:=x[i];inc(j);end;
if j<=m then ok:=true else ok:=false;
end;
procedure cha(l,r:longint);
var
mid:longint;
begin
if l<>r then
begin
mid:=(l+r)div 2;
if ok(mid) then cha(l,mid) else cha(mid+1,r);
end
else writeln(f2,l);
end;
begin
assign(f1,'expense.in');assign(f2,'expense.out');
reset(f1);rewrite(f2);
read(f1,n,m);
for a:=1 to n do
begin
read(f1,x[a]);
inc(sum,x[a]);
end;
cha(1,sum);
close(f1);close(f2);
end.