let words str =
  let len = String.length str in
  let buf = Buffer.create 10 in
  let rec loop acc = function
      i when i = len -> acc, (Buffer.contents buf |> int_of_string)
    | i ->
      loop
        (match str.[i] with
         | ' ' ->
           let v = Buffer.contents buf |> int_of_string in
           Buffer.clear buf; v
         | c ->
           Buffer.add_char buf c; acc)
        (i+1)
  in loop 0 0

let bsearch predicate maxv =
  let rec loop minp maxp =
    let middle =
      match maxp+minp with
        v when v mod 2 = 0 -> v/2
      | v -> v/2 + 1 in
    if middle = maxp then (if predicate minp then minp else maxp) else
      match predicate middle with
        true -> loop minp middle
      | false -> loop middle maxp
  in
  loop 1 maxv

let check num_of_truck goods capacity =
  let len = Array.length goods in
  let rec loop acc = function
      _, i when i >= len -> true
    | 0, _  -> false
    | rem_truck, i -> match goods.(i)+acc with
        x when x > capacity -> loop 0 (rem_truck-1,i)
      | x -> loop x (rem_truck,i+1)
  in
  loop 0 (num_of_truck,0)

let () =
  let n,num_of_truck = read_line () |> words in
  let goods = Array.init n (fun _ -> read_int ()) in
  let sum = Array.fold_left (fun acc v -> acc+v) 0 goods in
  bsearch (check num_of_truck goods) sum |> Printf.printf "%d\n"