#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

struct su {
    LL x,v;
};

void solve() {
    LL n,c;
    cin >> n >> c;
    LL ans = 0;
    LL x,v;
    vector<su> s(n);
    REP(i,0,n) {
        cin >> x >> v;
        s[i].x = x;
        s[i].v = v;
        ans += v;
    }
    ans -= (c - min(s[0].x, c - s[n-1].x));
    //cerr << ans << endl;
    VLL cw(n), ccw(n), mcw(n), mccw(n);
    cw[0] = s[0].v - s[0].x;
    ccw[0] = s[n-1].v - (c - s[n-1].x);
    //cerr << cw[0]<< "," << ccw[0] << endl;
    REP(i,1,n) {
        cw[i] = cw[i-1] + s[i].v - (s[i].x - s[i-1].x);
        ccw[i] = ccw[i-1] + s[n-1-i].v - (s[n-i].x - s[n-i-1].x);
        ans = max({ans, cw[i], ccw[i]});
        //cerr << cw[i]<< "," << ccw[i] << endl;
    }
    REP(i,0,n) {
        if (cw[i] > cw[mcw[i-1]]) mcw[i] = i;
        else mcw[i] = mcw[i-1];
        if (ccw[i] > ccw[mccw[i-1]]) mccw[i] = i;
        else mccw[i] = mccw[i-1];
    }
    {
        REP(i,0,n-1) {
            LL tmp = max(cw[i] - s[i].x, (LL)0) + max(ccw[mcw[n-i-2]], (LL)0);
            ans = max(ans, tmp);
            //cerr << i << "," << tmp << endl;
        }
    }
    {
        REP(i,0,n-1) {
            LL tmp = max(ccw[i] - (c - s[n-i-1].x), (LL)0) + max(cw[mcw[n-i-2]], (LL)0);
            ans = max(ans, tmp);
            //cerr << i << "," << tmp << endl;
        }
    }
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}