#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
ll n,c,x[100010],v[100010];
ll F(){
    ll cnt=0;
    lol(i,n)cnt+=v[i];
    cnt-=2*(c-x[0]);
    
    ll ans=cnt;
    
    ll sum=0,maxi=0;
    x[n]=c;
    //cout<<"#"<<cnt<<endl;
    
    for(int k=0;k<n;k++){
	sum+=v[k];
	maxi=max(maxi,sum-x[k]);
	
	cnt-=v[k];
	cnt+=2*(x[k+1]-x[k]);
	
	//cout<<"#"<<cnt<<" "<<sum<<" "<<maxi<<endl;
	ans=max(ans,cnt+maxi);
    }
    return ans;
}
int main(){
    cin>>n>>c;
    lol(i,n)cin>>x[i]>>v[i];
    ll ans=F();
    lol(i,n){
	x[i]=c-x[i];
	if(i<n/2)swap(v[i],v[n-1-i]);
    }
    sort(x,x+n);
    ans=max(ans,F());
    cout<<ans<<endl;
    return 0;
}
