#include using namespace std; #define int long long signed main() { int n, d; cin >> n >> d; vector t(n), k(n); for(int i = 0; i < n; ++i) cin >> t[i] >> k[i]; vector > dp(2, vector(n+1, -1)); dp[0][0] = 0; dp[1][0] = -(1LL<<55); for(int i = 0; i < n; ++i) { dp[0][i+1] = max(dp[0][i]+t[i], dp[1][i]+t[i]-d); dp[1][i+1] = max(dp[0][i]+k[i]-d, dp[1][i]+k[i]); } cout << max(dp[0][n], dp[1][n]) << endl; return 0; }