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

int main(){
    ll N, C, ans=0;
    cin>>N>>C;
    vector<ll>X(N+2, 0), V(N+2, 0);
    X[N+1]=C;
    for(int i=1;i<=N;i++){
        cin>>X[i]>>V[i];
    }
    vector<ll>CW(N+2, 0);
    for(ll i=1, cal=0;i<=N;i++){
        cal += (V[i] - X[i] + X[i-1]);
        ans = max(ans, cal);
        CW[i] = max(CW[i-1], cal - X[i]);
    }
    vector<ll>RW(N+2, 0);
    for(ll i=N, cal=0;i>=1;i--){
        cal += (V[i] + X[i] - X[i+1]);
        ans = max(ans, cal);
        ans = max(ans, cal + CW[i-1]);
        RW[i] = max(RW[i+1], cal - C + X[i]);
    }
    for(ll i=1, cal=0;i<=N;i++){
        cal += (V[i] - X[i] + X[i-1]);
        ans = max(ans, cal);
        ans = max(ans, cal + RW[i+1]);
        CW[i] = max(CW[i-1], cal - X[i]);
    }
    

    cout<<ans<<endl;
    return 0;
}