#define m(a,b)(a=a<b?b:a)
long c,x[1<<17],v[1<<17],s,L,R,r,l;i;main(n){for(scanf("%d%ld",&n,&c);~scanf("%ld%d",x+i,v+i);)L+=v[i++];for(;i--;){L-=v[i];R+=v[i];m(s,L-!!i*x[i-1]*2+m(r,R-(c-x[i])));}for(;i<n;){L+=v[i];R-=v[i++];m(s,R-(i!=n-1)*(c-x[i])*2+m(l,L-x[i-1]));}printf("%ld",s);}