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