#include using namespace std; typedef long long ll; const ll INF = 1LL << 60; ll dp[101][2]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, D; cin >> N >> D; fill((ll*)begin(dp), (ll*)end(dp), -INF); dp[0][0] = 0; for(int i = 0; i < N; i++) { ll a[2]; cin >> a[0] >> a[1]; for(int j = 0; j < 2; j++) { if(dp[i][j] == -INF) continue; for(int k = 0; k < 2; k++) { ll sum = a[k]; if(j != k) sum -= D; dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + sum); } } } cout << max(dp[N][0], dp[N][1]) << endl; }