program expense;
type
fxz=array[1..100000] of longint;
var
f1,f2:text;
n,m,max,ans,i,x:longint;
a:fxz;
procedure chu(l,r:longint);
var
flag:boolean;
procedure pan(xx:longint);
var
i,p:longint;
ls:fxz;
begin flag:=false;p:=1;
for i:=1 to n do ls[i]:=0;
for i:=1 to n do begin
while (ls[p]+a[i]>xx)and(p<=m) do inc(p);
if p<=m then ls[p]:=ls[p]+a[i]
else break;
end;
if p<=m then flag:=true;
end;
begin if l=r then ans:=l
else begin x:=(l+r) div 2;
flag:=false;
pan(x);
if flag then chu(l,x)
else chu(x+1,r);
end;
end;
begin assign(f1,'expense.in');
assign(f2,'expense.out');
reset(f1);rewrite(f2);
readln(f1,n,m);
max:=0;
for i:=1 to n do
begin readln(f1,a[i]);
max:=a[i]+max;
end;
chu(1,max);
writeln(f2,ans);
close(f1);close(f2);
end.