#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
using namespace std;
typedef long long ll;
int n;
ll c;
ll x[maxn],v[maxn];
ll sum1[maxn],sum2[maxn],ans=0;
int main()
{
	scanf("%d%lld",&n,&c);
	for(int i=1;i<=n;i++)   scanf("%lld%lld",&x[i],&v[i]);
	for(int i=1;i<=n;i++)   sum1[i]=sum1[i-1]-(x[i]-x[i-1])+v[i];
	x[n+1]=c;
	for(int i=n;i>=1;i--)   sum2[i]=sum2[i+1]-(x[i+1]-x[i])+v[i];
	for(int i=1;i<=n;i++)   sum1[i]=max(sum1[i],sum1[i-1]);
	for(int i=n;i>=1;i--)   sum2[i]=max(sum2[i],sum2[i+1]);
	ans=max(ans,max(sum1[n],sum2[1]));
	for(int i=0;i<=n;i++)
	{
		ans=max(ans,sum1[i]-x[i]+sum2[i+1]);
	}
	for(int i=n;i>=0;i--)
	{
		ans=max(ans,sum2[i]-(c-x[i])+sum1[i-1]);
	}
	printf("%lld\n",ans);
	return 0;
}
/*
15 100
4 10
8 10
19 10
24 10
29 10
33 10
37 10
38 10
40 10
41 10
52 10
66 10
80 10
93 10
97 10
*/