#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
P dp[100009][2];
int n,c,w[100009],v[100009],ans=0;

int Dist(int a,int b){
	if(a>b)swap(a,b);
	return min(abs(w[a]-w[b]),w[a]+abs(w[b]-c));
}
main(){
	cin>>n>>c;
	r(i,n)cin>>w[i]>>v[i];
	r(i,n)r(j,2)dp[i][j]=P(-1,-(int)1e17);
	dp[0][0]=P(0,v[0]-abs(w[0]));
	dp[0][1]=P(n-1,v[n-1]-abs(w[n-1]-c));
	for(int i=0;i<n-1;i++){
		for(int j=0;j<2;j++){
			int dist;
			//cout<<i<<' '<<dp[i][j].second<<endl;
			if(j==0){
				int now=dp[i][0].first;
				int cost=dp[i][0].second;

				int next=(now+1)%n;

				dist=Dist(now,next);
				//cout<<dist<<endl;

				int ncos=cost+(v[next]-dist);
				ans=max(ncos,ans);
				//zcout<<cost<<' '<<ncos<<endl;

				if(dp[i+1][0].second<ncos)dp[i+1][0]=P(next,ncos);

				next=(now-(i+1)+n)%n;//cout<<next<<endl;

				dist=Dist(now,next);

				ncos=cost+(v[next]-dist);
				ans=max(ncos,ans);

				if(dp[i+1][1].second<ncos)dp[i+1][1]=P(next,ncos);
				
			}
			else{
				int now=dp[i][1].first;
				int cost=dp[i][1].second;
				int next=(now-1+n)%n;

				dist=Dist(now,next);

				int ncos=cost+(v[next]-dist);
				ans=max(ncos,ans);

				if(dp[i+1][1].second<ncos)dp[i+1][1]=P(next,ncos);

				next=(now+(i+1))%n;

				dist=Dist(now,next);

				ncos=cost+(v[next]-dist);

				ans=max(ncos,ans);

				if(dp[i+1][0].second<ncos)dp[i+1][0]=P(next,ncos);
			}
		}//cout<<endl;
	}
	int ans=0;

	//cout<<n-1<<' '<<dp[n-1][0].second<<endl;
	//cout<<n-1<<' '<<dp[n-1][1].second<<endl;

	r(i,n)r(j,2){
		ans=max(dp[i][j].second,ans);
	}

	cout<<ans<<endl;
}