#include<bits/stdc++.h>
using namespace std;

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct segmentTree{

    int N;
    vector< pair<long long, int> > mini, maxi;
    vector<long long> sum;
    const long long INF = 2e18;
    
    void init(int siz){
        N = 1;
        while(N < siz){
            N <<= 1;
        }
        mini.resize(N * 2 - 1, {INF, -1});
        maxi.resize(N * 2 - 1, {-INF, -1});
        sum.resize(N * 2 - 1);
        return;
    }

    void build(vector<long long> &dat){
        init(dat.size());
        for(int i = 0, len = dat.size() ; i < len ; ++i){
            mini[i + N - 1] = {dat[i], i};
            maxi[i + N - 1] = {dat[i], i};
            sum[i + N - 1] = dat[i];
        }
        for(int i = N - 2 ; i >= 0 ; --i){
            mini[i] = min(mini[i * 2 + 1], mini[i * 2 + 2]);
            maxi[i] = max(maxi[i * 2 + 1], maxi[i * 2 + 2]);
            sum[i] = sum[i * 2 + 1] + sum[i * 2 + 2];
        }
    }

    void update(int k, long long x){
        k += N - 1;
        mini[k].first = x;
        maxi[k].first = x;
        sum[k] = x;
        while(k > 0){
            k = (k - 1) / 2;
            mini[k] = min(mini[k * 2 + 1], mini[k * 2 + 2]);
            maxi[k] = max(maxi[k * 2 + 1], maxi[k * 2 + 2]);
            sum[k] = sum[k * 2 + 1] + sum[k * 2 + 2];
        }
    }

    pair<long long, int> getMin(int a, int b, int k, int l, int r){
        if(r <= a || b <= l){
            return {INF, -1};
        }
        if(a <= l && r <= b){
            return mini[k];
        }
        pair<long long, int> vl = getMin(a, b, k * 2 + 1, l, (l + r) / 2);
        pair<long long, int> vr = getMin(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }

    pair<long long, int> getMin(int a, int b){
        if(a >= b){
            return {LLINF, 0};
        }
        return getMin(a, b, 0, 0, N);
    }

    pair<long long, int> getMax(int a, int b, int k, int l, int r){
        if(r <= a || b <= l){
            return {-INF, -1};
        }
        if(a <= l && r <= b){
            return maxi[k];
        }
        pair<long long, int> vl = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
        pair<long long, int> vr = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(vl, vr);
    }

    pair<long long, int> getMax(int a, int b){
        if(a >= b){
            return {-1LL, 0};
        }
        return getMax(a, b, 0, 0, N);
    }

    long long getSum(int a, int b, int k, int l, int r){
        if(r <= a || b <= l){
            return 0LL;
        }
        if(a <= l && r <= b){
            return sum[k];
        }
        long long vl = getSum(a, b, k * 2 + 1, l, (l + r) / 2);
        long long vr = getSum(a, b, k * 2 + 2, (l + r) / 2, r);
        return vl + vr;
    }

    long long getSum(int a, int b){
        if(a >= b){
            return 0LL;
        }
        return getSum(a, b, 0, 0, N);
    }

};

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    lint c;
    cin >> n >> c;

    vector<lint> x(n * 2 + 1), v(n * 2 + 1);
    reps(i, n){
        cin >> x[i] >> v[i];
        x[i + n] = x[i] + c;
        v[i + n] = v[i];
    }
    reps(i, n * 2){
        v[i] += v[i - 1];
    }

    lint ans = 0;

    segmentTree seg;
    vector<lint> dat(n * 2 + 1);
    rep(i, n * 2 + 1){
        dat[i] = v[i] - abs(c - x[i]);
    }
    seg.build(dat);

    reps(i, n){
        chmax(ans, v[n] - v[i - 1] - abs(c - x[i]));
        chmax(ans, seg.getMax(n + 1, i + n).first - v[i - 1] - abs(c - x[i]) * 2LL);
    }

    fill(dat.begin(), dat.end(), 0LL);
    reps(i, n * 2){
        dat[i] = v[i - 1] + abs(c - x[i]);
    }
    seg.build(dat);

    REP(i, n + 1, n * 2 + 1){
        chmax(ans, v[i] - v[n] - abs(c - x[i]));
        chmax(ans, v[i] - seg.getMin(i - n + 1, n + 1).first - abs(c - x[i]) * 2LL);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 25472