#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    ll n, d;
    cin >> n >> d;
    ll dp[2] = {0, -d};
    REP(i, n){
        ll t, k;
        cin >> t >> k;
        
        ll tmp[2];
        tmp[0] = max(dp[0] + t, dp[1] + k - d);
        tmp[1] = max(dp[1] + k, dp[0] + t - d);
        dp[0] = tmp[0];
        dp[1] = tmp[1];
    }
    cout << max(dp[0], dp[1]) << endl;
}