// Original C++ solution (slower):
#include <iostream>

#include <utility>

#include <vector>

#include <algorithm>



using namespace std;



int main(void) {

    long long n,c,x[100000],v[100000],s[2][100001],m[2][100001],d[2][100001] = {0};

    cin >> n >> c;

    for(long long i = 0;i < n;i++)

        cin >> v[i] >> x[i];

    s[0][0] = 0;

    for(long long i = 1;i <= n;i++)

        s[0][i] = s[0][i-1] + x[i-1];

    for(long long i = 1;i <= n;i++)

        s[0][i] = s[0][i] - v[i-1];

    s[1][0] = 0;

    for(long long i = 1;i <= n;i++)

        s[1][i] = s[1][i-1] + x[n-i];

    for(long long i = 1;i <= n;i++)

        s[1][i] = s[1][i] - (c - v[n-i]);

    vector<pair<long long,long long>> p[2];

    for(long long i = 0;i <= n;i++) {

        p[0].push_back(make_pair(s[0][i], i));

        p[1].push_back(make_pair(s[1][i], i));

    }

    sort(p[0].begin(), p[0].end(),greater<pair<long long,long long>>());

    sort(p[1].begin(), p[1].end(),greater<pair<long long,long long>>());

    long long z = n;

    for(auto itr = p[0].begin();itr < p[0].end();itr++) {

        if(itr->second <= z) {

            for(long long i = itr->second;i <= z;i++) {

                m[0][i] = itr->first;

                if(i != 0 && itr->second != 0)

                    d[0][i] = v[itr->second - 1];

                else

                    d[0][i] = 0;

            }

            z = itr->second - 1;

        }

    }

    z = n;

    for(auto itr = p[1].begin();itr < p[1].end();itr++) {

        if(itr->second <= z) {

            for(long long i = itr->second;i <= z;i++) {

                m[1][i] = itr->first;

                if(i != 0 && itr->second != 0)

                    d[1][i] = c - v[n - itr->second];

                else

                    d[1][i] = 0;

            }

            z = itr->second - 1;

        }

    }

    

    long long retval = 0;

    for(long long i = 0;i <= n;i++) {

        retval = max(retval,m[0][i] + m[1][n-i] - min(d[0][i],d[1][n-i]));

        retval = max(retval,m[1][i] + m[0][n-i] - min(d[1][i],d[0][n-i]));

    }

    cout << retval << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#define loop(i, s, e) for(ll i = s;i < e;i++)



#include <iostream>

#include <iomanip>

#include <set>

#include <vector>

#include <queue>

#include <stack>

#include <utility>

#include <algorithm>

#include <map>

#include <cmath>

//#include "vector2d.cpp"



using namespace std;

//using namespace libcgl;

typedef long long signed ll;



long long n,c,v[200000],x[200000],s[2][200000],d[2][200000],ss[2][200000],dd[2][200000];



long long xx(int i) {

    if(i == 0) return 0;

    if(i < 0) return c-x[n+i+1];

    return x[i];

}





long long vv(int i) {

    if(i == 0) return 0;

    if(i < 0) return v[n+i+1];

    return v[i];

}



int main() {

    cin >> n >> c;

    loop(i,1,n+1) { cin >> x[i] >> v[i]; }



    loop(i,1,n+1) {

        s[0][i] = s[0][i-1] + vv(i) - (xx(i) - xx(i-1));

        d[0][i] = d[0][i-1] + vv(-i) - (xx(-i) - xx(-i+1));

        ss[0][i] = max(ss[0][i-1],s[0][i]);

        dd[0][i] = max(dd[0][i-1],d[0][i]);

        s[1][i] = s[1][i-1] + vv(i) - 2 * (xx(i) - xx(i-1));

        d[1][i] = d[1][i-1] + vv(-i) - 2 * (xx(-i) - xx(-i+1));

        ss[1][i] = max(ss[1][i-1],s[1][i]);

        dd[1][i] = max(dd[1][i-1],d[1][i]);

    }



    ll res = 0;

    loop(i,0,n+1) {

        res = max(res,max(ss[1][i] + dd[0][n-i],ss[0][i] + dd[1][n-i]));

    }

    cout << res << endl;

}




// Fastest known solution for this problem: