# ALDS1_4_D: Allocation

def loadable_num(n_trucks, load_weights, capacity)
  w_loaded = 0
  n_trucks_loaded = 0
  load_weights.each_with_index do |weight, i|
    return i if capacity < weight
    w_loaded += weight
    if capacity < w_loaded
      w_loaded = weight
      n_trucks_loaded += 1
      return i if n_trucks == n_trucks_loaded
    end
  end
  load_weights.size
end

def find_min_capacity(n_trucks, load_weights, capacity = 1)
  if load_weights.size <= loadable_num(n_trucks, load_weights, capacity)
    capacity
  else
    find_min_capacity n_trucks, load_weights, capacity + 1
  end
end

n_loads, n_trucks = gets.split.map &:to_i
load_weights = n_loads.times.map do
  gets.chomp.to_i
end

puts find_min_capacity(n_trucks, load_weights)