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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

bool pc(const pair<lint,lint>& a,const pair<lint,lint>& b){
    return a.second<b.second;
}
bool gpc(const pair<lint,lint>& a,const pair<lint,lint>& b){
    return a.second>b.second;
}

int main(){
    ulint N,C;
    ulint x[100002],v[100002];
    cin >> N >> C;
    x[0]=v[0]=0LL;
    x[N+1]=C;
    v[N+1]=0LL;
    for(lint i=1;i<=N;i++) cin >> x[i] >> v[i];

    pair<lint,lint> right[100002],left[100002],rb[100002],lb[100002];
    right[0]=rb[0]=make_pair(0,0);
    left[N+1]=lb[N+1]=make_pair(0,0);

    for(lint i=1;i<=N+1;i++){
        right[i]=make_pair(right[i-1].first+v[i]-(x[i]-x[i-1]),i);
        rb[i]=make_pair(right[i-1].first+v[i]-(x[i]-x[i-1])-x[i],i);
    }
    for(lint i=N;i>=0;i--){
        left[i]=make_pair(left[i+1].first+v[i]-(x[i+1]-x[i]),i);
        lb[i]=make_pair(left[i+1].first+v[i]-(x[i+1]-x[i])-(C-x[i]),i);
    }
    sort(right,right+N+2,greater<pair<lint,lint>>());
    sort(left,left+N+2,greater<pair<lint,lint>>());

    lint best=max(right[0].first,left[0].first);
    for(int i=1;i<=N;i++){
        if(rb[i].first>0){
            //best=max(best,rb[i].first+lower_bound(left,left+N+2,rb[i].second+1,pc)->first);
        }
        if(lb[i].first>0){
            best=max(best,lb[i].first+lower_bound(right,right+N+2,lb[i].second+1,gpc)->first);
            for(int j=0;j<=N+1;j++){
                if(right[j].second<lb[i].second){
                    best=max(best,lb[i].first+right[j].first);
                    break;
                }
            }
        }
    }
    cout << best << endl;
/*
    if(left[N+1].second<=right[N+1].second){
        cout << max(left[N+1].first,right[N+1].first);
    }else{
        lint X=right[N+1].first+left[N+1].first-x[right[N+1].second];
        lint Y=right[N+1].first+left[N+1].first-(C-x[left[N+1].second]);
        cout << max(max(X,Y),max(left[N+1].first,right[N+1].first));
    }
*/
    return 0;
}