Program expense;
Type
sc=array [1..100000] of longint;
Var
s:sc;
i,j,k,p:longint;
n,m:longint;
max,h:longint;
z,temp:longint;
Begin
assign(input,'expense.in');
assign(output,'expense.out');
reset(input);
rewrite(output);
readln(n,m);
max:=0;
h:=0;
for i:=1 to n do begin
readln(s[i]);
if s[i]>max then max:=s[i];
h:=h+s[i];
end;
i:=max;
j:=h;
while i<j do begin
k:=(i+j) div 2;
z:=0;
temp:=0;
for p:=1 to n do begin
temp:=temp+s[p];
if temp>k then begin
temp:=s[p];
z:=z+1;
end;
end;
if z<m then j:=k
else i:=k+1;
end;
writeln(j);
close(input);
close(output);
End.