#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define FOR(I,A,B) for(int I = int(A); I < int(B); ++I) int main(){ ll n,d; cin >> n >> d; vector T(n),K(n); FOR(i,0,n) cin >> T[i] >> K[i]; ll dp[n][2]; dp[0][0] = T[0]; dp[0][1] = K[0]-d; FOR(i,1,n){ dp[i][0] = max(dp[i-1][0]+T[i],dp[i-1][1]+T[i]-d); dp[i][1] = max(dp[i-1][0]+K[i]-d,dp[i-1][1]+K[i]); } cout << max(dp[n-1][0],dp[n-1][1]) << endl; }