#include<bits/stdc++.h>
using namespace std;
int main(){
int pricesSize,fee;
cin >> pricesSize >> fee;
int prices[pricesSize];
for(int i = 0;i < pricesSize;i ++)
cin >> prices[i];
int hode = INT_MIN + fee,cash = 0,i = 0,bh_hode = hode;
for(i = 0;i < pricesSize;i++){
hode = max(hode,cash - prices[i]);
cash = max(bh_hode + prices[i] - fee,cash);
bh_hode = hode;
}
cout << cash;
return 0;
}