let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let solve n k =
  let a = Array.init n (fun _ -> read_int ()) in
  let rec check = function
    | (i, _, _, _) when i = n -> n
    | (i, j, _, _) when j >= k -> i
    | (i, j, s, p) when s + a.(i) <= p -> check (i + 1, j, s + a.(i), p)
    | (i, j, _, p) -> check (i, j + 1, 0, p) in
  let rec bin_search l r =
    if r < l then l
    else
      let m = (l + r) / 2 in
      if check (0, 0, 0, m) >= n then bin_search l (m - 1)
      else bin_search (m + 1) r in
  Printf.printf "%d\n" (bin_search 0 (100000 * 10000))

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; k] -> solve n k
  | _ -> exit 1