# Arup Guha
# 1/25/2025
# Solution to Kattis Problem: Radio Commericials
# https://open.kattis.com/problems/commercials

# Get basic input.
toks = input().split()
n = int(toks[0])
cost = int(toks[1])

# Read in values.
vals = [int(x) for x in input().split()]

# Treat each commericial as net profit instead of total.
for i in range(n):
    vals[i] -= cost

# Run MCSS on this adjusted sequence.
res = 0
tot = 0
for i in range(n):

    # Add and update if necessary.
    tot += vals[i]
    res = max(res, tot)

    # Chop off the negative prefix, if necessary.
    if tot < 0:
        tot = 0

# Ta da!
print(res)
