#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=1e5+9;
LL c,ans,n;
LL x[maxn],v[maxn];
struct node{
	LL CW,AC,CW_back,AC_back;
}f[maxn];
LL read(){
	LL x=0;bool f=0;char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') f=1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return f?-x:x;
}
int main(){
	n=read(),c=read();
	for (int i=1;i<=n;++i) x[i]=read(),v[i]=read();
	f[1].AC=v[1]-x[1];
	for (int i=2;i<=n;++i) f[i].AC=f[i-1].AC+v[i]-(x[i]-x[i-1]),f[i].AC_back=f[i].AC-x[i];
	for (int i=2;i<=n;++i) f[i].AC=max(f[i-1].AC,f[i].AC),f[i].AC_back=max(f[i-1].AC_back,f[i].AC_back);
	f[n].CW=v[n]-(c-x[n]);
	for (int i=n-1;i>=1;--i) f[i].CW=f[i+1].CW+v[i]-(x[i+1]-x[i]),f[i].CW_back=f[i].CW-x[i];
	for (int i=n-1;i>=1;--i) f[i].CW=max(f[i+1].CW,f[i].CW),f[i].CW_back=max(f[i+1].CW_back,f[i].CW_back);
	for (int i=1;i<n;++i){
		ans=max(ans,f[i].AC);
		ans=max(ans,f[i].CW);
		ans=max(ans,f[i].AC_back+f[i+1].CW);
		ans=max(ans,f[i].AC+f[i+1].CW_back);
	}
	ans=max(ans,f[n].AC); ans=max(ans,f[n].CW);
	cout<<ans<<endl;
	return 0;
}