#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { int n, d; cin >> n >> d; int t[n], k[n]; rep(i,n)cin >> t[i] >> k[i]; int dp[n][2]; dp[0][0] = t[0]; dp[0][1] = k[0] - d; srep(i,1,n){ dp[i][0] = max(dp[i-1][0] + t[i], dp[i-1][1] - d + t[i]); dp[i][1] = max(dp[i-1][0] - d + k[i], dp[i-1][1] + k[i]); } int ans = max(dp[n-1][0], dp[n-1][1]); cout << ans << endl; return 0; }