#include using namespace std; int main(){ int N, D; cin >> N >> D; vector T(N),K(N); for(int i = 0; i < N; i++) cin >> T.at(i) >> K.at(i); vector> dp(N+1, vector(2,-(1LL << 60))); dp.at(0).at(0) = 0; for(int i = 0; i < N; i++){ dp.at(i+1).at(0) = max(dp.at(i).at(1) - D + T.at(i), dp.at(i).at(0) + T.at(i)); dp.at(i+1).at(1) = max(dp.at(i).at(0) - D + K.at(i), dp.at(i).at(1) + K.at(i)); } cout << max(dp.at(N).at(0), dp.at(N).at(1)) << endl; }