program bing;
var
f1,f2:text;
n,m,max,min,mid,i,j,k,t:longint;
a:array[1..100000] of integer;
begin
assign(f1,'expense.in');reset(f1);
assign(f2,'expense.out');rewrite(f2);
readln(f1,n,m);
max:=0;min:=0;
for i:=1 to n do
begin
readln(f1,a[i]);
max:=max+a[i];
if a[i]>min then min:=a[i];
end;
while min<max do
begin
mid:=(min+max)div 2;
t:=0;k:=0;
for i:=1 to n do
begin
t:=t+a[i];
if t>mid then
begin
inc(k);
t:=a[i];
end;
end;
if k>=m then min:=mid+1 else max:=mid;
end;
writeln(f2,max);
close(f1);close(f2);
end.