N, M = gets.split.map(&:to_i) A = gets.split.map(&:to_i) def f(x) stock = 0 cost = x * M A.each do |a| return false if (a + stock) < cost if cost <= a stock += a - cost else r = cost - a stock -= r end end true end ok = 0 ng = 10 ** 18 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if f(x) ok = x else ng = x end end puts ok