def can_put?(wmax, k, wi)
  cap = 0
  num = 1
  wi.each do |w|
    cap += w
    if cap > wmax
      cap = w
      num += 1
      return false if num > k || cap > wmax
    end
  end
  num <= k
end

def solve(k, wi)
  lb, ub = 0, wi.inject(&:+)
  while ub - lb > 1
    mid = (ub+lb)/2
    if can_put?(mid, k, wi)
      ub = mid
    else
      lb = mid
    end
  end
  ub
end

n, k = gets.split(" ").map(&:to_i)
wi = Array.new(n) { gets.to_i }
puts solve(k, wi)

