//void __(){
//    _(ll,n);
//    _(ll,c);
//    _(vpll,a,n);
//    n += 2;
//    a.insert(a.begin(),{0,0});
//    a.pb({c,0});
//    vl pl(n),pr(n);
//    vl l2(n),r2(n);
//
//    rep(i,n) pl[i] = a[i].Y + (i > 0 ? pl[i-1] : 0);
//    per(i,n) pr[i] = a[i].Y + (i < n-1 ? pr[i+1] : 0);
//
//    rep(i,n){
//        l2[i] = pl[i]-2*a[i].X;
//        r2[i] = pr[i]-2*(c-a[i].X);
//    }
//    rep(i,1,n-1) l2[i] = max(l2[i],l2[i-1]);
//    per(i,n-1)   r2[i] = max(r2[i],r2[i+1]);
//
//    ll ans = 0;
//    rep(i,n-1)   ans = max(ans,pl[i]-   a[i].X +r2[i+1]);
//    rep(i,1,n-1) ans = max(ans,pr[i]-(c-a[i].X)+l2[i-1]);
//    print ans;
//
//}
//
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define REP_ZERO_INT(i,r) for(int i = 0; i < r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define PER_ZERO_INT(i,r) for(int i = r-1; i >= 0; --i)
#define GET_PER_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define per(...) GET_PER_MACRO(__VA_ARGS__,PER_ANY,PER_INT,PER_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define X first
#define Y second
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
template <typename F, typename S> static
istream& operator>>(istream& stream, pair<F, S>& t){
    return stream >> t.first >> t.second;
}
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }
    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
void __(){
    _(ll,n);
    _(ll,c);
    _(vpll,a,n);
    n += 2;
    a.insert(a.begin(),{0,0});
    a.pb({c,0});
    vl pl(n),pr(n);
    vl l2(n),r2(n);
    rep(i,n) pl[i] = a[i].Y + (i > 0 ? pl[i-1] : 0);
    per(i,n) pr[i] = a[i].Y + (i < n-1 ? pr[i+1] : 0);
    rep(i,n){
        l2[i] = pl[i]-2*a[i].X;
        r2[i] = pr[i]-2*(c-a[i].X);
    }
    rep(i,1,n-1) l2[i] = max(l2[i],l2[i-1]);
    per(i,n-1)   r2[i] = max(r2[i],r2[i+1]);
    ll ans = 0;
    rep(i,n-1)   ans = max(ans,pl[i]-   a[i].X +r2[i+1]);
    rep(i,1,n-1) ans = max(ans,pr[i]-(c-a[i].X)+l2[i-1]);
    print ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}


Measured memory_bytes: 6244