#include using namespace std; using ll = long long; int main(){ int n , d; cin >> n >> d; vector> dp(n + 10 , vector(2 , 0)); for(int i = 0; i < n; i++){ ll a , b; cin >> a >> b; if(i == 0){ dp[0][0] = a; dp[0][1] = b - d; }else{ dp[i][0] = max(dp[i - 1][0] + a , dp[i - 1][1] + a - d); dp[i][1] = max(dp[i - 1][1] + b , dp[i - 1][0] + b - d); } } cout << max(dp[n - 1][0] , dp[n - 1][1]) << endl; return 0; }