program expense;
var
i,x,j,t,n,m,max:longint;
a:array[0..10001] of integer;
procedure fenzu(ii:longint);
var
ss:longint;
begin
t:=0;
ss:=0;
for i:=1 to n do
begin
if ss+a[i]<=ii then ss:=ss+a[i]
else
begin
inc(t);
ss:=a[i];
end;
end;
end;
procedure erfen(l1,l2:longint);
begin
if l1=l2 then
begin
write(l1);
close(input);
close(output);
halt;
end;
fenzu(((l1-l2) div 2+l2));
if t<=m then
erfen(((l1-l2) div 2+l2),l2)
else
erfen(l1,((l1-l2) div 2+l2));
end;
begin
assign(input,'expense.in');
assign(output,'expense.out');
reset(input);
rewrite(output);
read(n,m);
for i:=1 to n do
begin
readln(a[i]);
max:=max+a[i];
if a[i]>x then x:=a[i];
end;
erfen(max,x);
close(input);
close(output);
end.