//Nobody_hacks_me
//by lzt
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;

#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define fuck cerr<<"fuck"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define lc (i<<1)
#define rc (i<<1|1)
#define clr(x) memset(x,0,sizeof(x))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
#define geti(x) x=read()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) print(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) print(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
#define rep(x,a,b) for(register int x=(int)a;x<=(int)b;x++)
#define rrep(x,a,b) for(register int x=(int)a;x>=(int)b;x--)

ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}

template<class T> inline void print(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}

const ll inf=2147483647;
const ll llinf=2e18;
const int mod=998244353;
const ull MAXMOD=(ull)mod*(mod-1);

//------------head-------------

//Problem No. 6

ll n,c;
pair<ll,ll> a[111111];
ll ans[111111];
ll res[111111];

int main(){
	#ifdef LZT
	freopen("in","r",stdin);
	#endif
	
	getii(n,c);
	rep(i,1,n)
		getii(a[i].x,a[i].y);
	sort(a+1,a+n+1);
	ll ans1=0,ans2=0,ans3=0;
	ll nw=0;
	ll pos=0;
	ll mxpos=0;
	rep(i,1,n){
		nw=nw+a[i].y-(a[i].x-pos);
		pos=a[i].x;
		if(nw>ans1) ans1=max(ans1,nw),mxpos=i;
		ans[i]=ans1;
	}
	
	ll mxpos2=0;
	nw=0,pos=c;
	rrep(i,n,1){
		nw=nw+a[i].y-(pos-a[i].x);
		pos=a[i].x;
		if(nw>ans2) ans2=max(ans2,nw),mxpos2=i;
		res[i]=ans2;
	}
	
	ll nwmx1=0,nwmx2=0;
	nw=res[1],pos=0;
	rep(i,1,n){
		if(a[i].x*2>c) break;
		nw=nw+a[i].y-(a[i].x-pos)*2+res[i+1]-res[i];
		pos=a[i].x;
		nwmx1=max(nwmx1,nw);
	}
	
	nw=ans[n],pos=c;
	rrep(i,n,1){
		if(a[i].x*2<c) break;
		nw=nw+a[i].y-(pos-a[i].x)*2+ans[i-1]-ans[i];
		pos=a[i].x;
		nwmx2=max(nwmx2,nw);
	}
	/*
	rep(i,1,n)
		puti(ans[i]);
	puts("");
	rep(i,1,n)
		puti(res[i]);
	puts("");
	putsii(nwmx1,nwmx2);*/
	ans3=max(nwmx1,nwmx2);
	
	putsi(max(ans1,max(ans3,ans2)));
	
	return 0;
}

Measured memory_bytes: 3456