#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 100000 + 233;
LL l[maxn],r[maxn],v[maxn],lsum[maxn],rsum[maxn],c,n,lmax1[maxn],lmax2[maxn],rmax1[maxn],rmax2[maxn];
int main(){
	scanf("%lld%lld",&n,&c);
	for(int i = 1;i <= n;++i){
		scanf("%lld%lld",&l[i],&v[i]);
		r[i] = c - l[i];
		lsum[i] = lsum[i - 1] + v[i];
	}
	for(int i = n;i >= 1;--i)rsum[i] = rsum[i + 1] + v[i];
	for(int i = 1;i <= n;++i){
		lmax1[i] = max(lmax1[i - 1],lsum[i] - l[i]);
		lmax2[i] = max(lmax2[i - 1],lsum[i] - 2*l[i]);
	}
	for(int i = n;i >= 1;--i){
		
		rmax1[i] = max(rmax1[i + 1],rsum[i] - r[i]);
		rmax2[i] = max(rmax2[i + 1],rsum[i] - 2*r[i]);
	}
	LL ans = 0;
	for(int i = 1;i <= n;++i){
		LL tmp = 0;
		tmp = max(lmax1[i],rmax1[i]);
		ans = max(ans,tmp);
		tmp = max(lmax1[i] + rmax2[i + 1],rmax1[i] + lmax2[i - 1]);
		ans = max(ans,tmp);
	}
	printf("%lld",ans);
	return 0;
}