#include using namespace std; #define int long long signed main(){ cin.tie(0); ios::sync_with_stdio(false); int n,d; cin >> n >> d; vector t(n),k(n); for(int i = 0; i < n; i++){ cin >> t[i] >> k[i]; } vector dp1(n+1); //tokyo vector dp2(n+1); //kyoto dp1[0] = 0; dp2[0] = -d; for(int i = 0; i < n; i++){ dp1[i+1] = max(dp1[i]+t[i],dp2[i]+t[i]-d); dp2[i+1] = max(dp2[i]+k[i],dp1[i]+k[i]-d); } cout << max(dp1[n],dp2[n]) << endl; return 0; }