#include<iostream>
using namespace std;
const int maxn = 1e5+10;
int n;
long long c, x[maxn], v[maxn], s1[maxn], s2[maxn];
int main()
{
	cin>>n>>c;
	for(int i=1; i<=n; i++) cin>>x[i]>>v[i];
	for(int i=1; i<=n; i++) s1[i] = s1[i-1] + v[i] - (x[i] - x[i-1]);
	x[n+1] = c;
	for(int i=n; i; i--) s2[i] = s2[i+1] + v[i] - (x[i+1] - x[i]);
	for(int i=2; i<=n; i++) s1[i] = max(s1[i-1], s1[i]);
	for(int i=n-1; i; i--) s2[i] = max(s2[i+1], s2[i]);
	long long ans = 0;
	for(int i=1; i<=n; i++) {
		ans = max(ans, s1[i] - x[i] + s2[i+1]);
		ans = max(ans, s2[i] - (c - x[i]) + s1[i-1]);
		ans = max(ans, s1[i]);
		ans = max(ans, s2[i]);
	}
	cout<<ans<<endl;
	return 0;
}