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 =
    match compare minp maxp with
      0 -> minp
    | _ ->
      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 rec loop acc = function
      _, [] -> true
    | 0, _  -> false
    | rem_truck, (first::rest as l) -> match first+acc with
        x when x > capacity -> loop 0 (rem_truck-1,l)
      | x -> loop x (rem_truck,rest)
  in
  loop 0 (num_of_truck,goods)

let set_goods n =
  let rec loop acc sum = function
      0 -> acc,sum
    | i ->
      let v = read_int () in
      loop (v::acc) (sum+v) (i-1)
  in
  loop [] 0 n

let abc sum goods =
  print_endline "fin"
    
let () =
  let n,num_of_truck = read_line () |> words in
  let goods,sum = set_goods n in
  bsearch (check num_of_truck goods) sum |> Printf.printf "%d\n"