def challenge_optimize(baggages, track_num, capacity)
	baggage_index = 0
	track_num.times do |track_index|
		loaded = 0
		while (loaded + baggages[baggage_index]) <= capacity
			loaded += baggages[baggage_index]
			baggage_index += 1
			return baggages.size if baggage_index == baggages.size
		end
	end
	baggage_index
end

MAX_NUM_OF_BAGGAGES = 100000
MAX_BAGGAGE_WEIGHT  = 10000
baggage_num, track_num = STDIN.gets.split[0...2].map(&:to_i)
baggages = []
baggage_num.times { baggages << STDIN.gets.to_i }

range = (0..MAX_NUM_OF_BAGGAGES * MAX_BAGGAGE_WEIGHT)
p range.bsearch { |n| challenge_optimize(baggages, track_num, n) >= baggage_num }