# ??????????????????????????????????????????????????????
def can_load? baggages, track_size, max_weight
  baggages = baggages.dup
  track_count = 1

  #puts "?????§??????????????°???#{track_size}?????¨????????°?????????????????????#{max_weight}"
  baggages.reduce(0) {|last, item|
    #puts "?????????: #{last}"
    weight = last + item
    # ????????????????????£???????¬????????????????????????????
    if weight > max_weight
      track_count += 1
      #puts "??????????????°?????? #{track_count}"
      next item
    end

    # ????????????????????????????¬??????????????????????
    weight
  }

  track_count <= track_size
end

def search baggages, track_size
  min = baggages.max
  max = baggages.reduce(0) {|sum, item| sum + item}
  #(min..max).each {|min_weight|
  #  can_load = can_load? baggages, track_size, min_weight
  #  #puts "????????????#{can_load}"
  #  return min_weight if can_load
  #}
  (min..max).bsearch{|min_weight| can_load? baggages, track_size, min_weight}
end

# ????°?????????????????????????????????????????????§???

# ?????§????????¨?????????

def main
  array = STDIN.read.split(/\n/)
  baggage_size, track_size = array.shift.split(' ').map{|s|s.to_i}
  baggages = array.map{|s|s.to_i}
  puts search baggages, track_size
end

main