N,M = map(int,input().split())
A = list(map(int,input().split()))

def check(L):
    stack = 0
    for a in A:
        if stack + a < L * M:
            return False
        else:
            stack = stack + a - L * M
    return True
end = 10 ** 9
start = -1
while end - start > 1:
    mid = (start + end) // 2
    if check(mid):
        end = mid
    else:
        start = mid
print(end)