#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int N, D;
vector<int> T;
vector<int> K;
int dp[2][100];

int move(int now, int day){
    if(dp[now][day] != -1){
        return dp[now][day];
    }else if(day == N){
        return dp[now][day] = 0;
    }else if(now == 0){
        return dp[now][day] = max(T[day] + move(0, day + 1), K[day] + move(1, day + 1) - D);
    }else{
        return dp[now][day] = max(K[day] + move(1, day + 1), T[day] + move(0, day + 1) - D);
    }
}

int main(){
    cin >> N >> D;
    for(int i = 0; i < N; i++){
        int tokyo, kyoto;
        cin >> tokyo >> kyoto;
        T.push_back(tokyo);
        K.push_back(kyoto);
    }
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 100; j++){
            dp[i][j] = -1;
        }
    }
    cout << move(0, 0) << endl;
}