open String
let f s=let r=ref[]and j=ref(length s)in for i=length s-1downto 0do if s.[i]=' 'then(r:=sub s(i+1)(!j-i-1)::!r;j:=i)done;sub s 0!j::!r
and g n k a=let rec($)l r=if r<l then l else if h(0,0,0,(l+r)/2)<n then((l+r)/2+1)$r else l$((l+r)/2-1)and h=function(i,j,x,p)->if i=n||j=k then i else if x+a.(i)<=p then h(i+1,j,x+a.(i),p)else h(i,j+1,0,p)in 0$1000000000;;match List.map int_of_string(f(read_line()))with[n;k]->Printf.printf"%d
"(g n k(Array.init n(fun _->read_int())))|_->()