// Arup Guha
// 2/18/2024
// Solution to Kattis Problem: Radio Commercials
// https://open.kattis.com/problems/commercials

import java.util.*;

public class commercials {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int p = stdin.nextInt();
		
		// Just store the net profit from each commercial.
		int[] arr = new int[n];
		for (int i = 0; i<n; i++) 
			arr[i] = stdin.nextInt()-p;
			
		int res = 0, cur = 0;
		
		// Run MCSS algorithm.
		for (int i=0; i<n; i++) {
		
			// Add to this streak.
			cur += arr[i];
			
			// Update max if necessary.
			res = Math.max(res, cur);
			
			// Time to rest.
			if (cur < 0) cur = 0;
		}
		
		// Ta da!
		System.out.println(res);
	}
}