// Arup Guha
// 6/15/2023
// Solution to SIUCF CP Contest 2 Problem: Radio Commericials
// https://open.kattis.com/problems/commercials

using namespace std;
#include <iostream>

int main() {

    // Set up MCSS.
    int n, p;
    cin >> n >> p;
    int res = 0, curS = 0;

    // Go through numbers.
    for (int i=0; i<n; i++) {

        // Just subtract out cost for net profit.
        int tmp;
        cin >> tmp;
        tmp -= p;

        // Update running sum, max, and reset to 0 if we fall below.
        curS += tmp;
        res = max(res, curS);
        if (curS < 0) curS = 0;
    }

    // Ta da!
    cout << res << endl;

    return 0;
}
