#include<bits/stdc++.h>

#define maxn 100000+5

using namespace std;

typedef long long LL;

LL l[maxn],r[maxn],x[maxn],v[maxn],c,ans,m1,m2;
int n;

int main(){
	cin >> n >> c;
	for(int i=1;i<=n;i++){
		cin >> x[i] >> v[i];
	}
	x[n+1]=c;
	for(int i=1;i<=n;i++)
		l[i]=l[i-1]+v[i]-(x[i]-x[i-1]);
	for(int i=1;i<=n;i++)
		l[i]=max(l[i-1],l[i]);
	for(int i=n;i>=1;i--)
		r[i]=r[i+1]+v[i]-(x[i+1]-x[i]);
	for(int i=n;i>=1;i--)
		r[i]=max(r[i+1],r[i]);
	for(int i=1;i<=n;i++){
		ans=max(ans,l[i]);
		ans=max(ans,l[i]+r[i+1]-x[i]);
	}
	for(int i=n;i>=1;i--){
		ans=max(ans,r[i]);
		ans=max(ans,r[i]+l[i-1]-(c-x[i]));
	}
	cout << ans;
	return 0;
} 