N, M = map(int, input().split()) A = list(map(int, input().split())) def ok(n): rest = 0 for a in A: a += rest if a < n: return False rest = a - n return True l = 0 r = 10 ** 10 while r - l > 1: m = (r + l) // 2 if ok(m): l = m else: r = m print(l // M)