#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll x[200000],v[200000];
ll a[200000],ma[200000];
ll b[200000],mb[200000];

signed main(){
	ll n,c;cin>>n>>c;
	rep(i,n){
		scanf("%lld%lld",&x[i],&v[i]);
	}
	ll cnt=0;
	for(int i=n-1;i>=0;i--)cnt+=v[i],a[i]=cnt-(c-x[i]);
	ma[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--)ma[i]=max(ma[i+1],a[i]);
	cnt=0;
	rep(i,n)cnt+=v[i],b[i]=cnt-x[i];
	mb[0]=b[0];
	for(int i=1;i<n;i++)mb[i]=max(mb[i-1],b[i]);
	ll ans=0;
	//最初に時計回り
	cnt=0;
	rep(i,n){
		cnt+=v[i];
		ans=max(ans,cnt-x[i]);
		if(i<n-1)ans=max(ans,cnt-x[i]*2+ma[i+1]);
	}
	//反時計
	cnt=0;
	for(int i=n-1;i>=0;i--){
		cnt+=v[i];
		ans=max(ans,cnt-(c-x[i]));
		if(i)ans=max(ans,cnt-(c-x[i])*2+mb[i-1]);
	}
	cout<<ans<<endl;
}