#include<bits/stdc++.h>
#define LL long long
#define maxn 100009
using namespace std;
struct data{
  LL x,v;
}t[maxn];
LL a[maxn],b[maxn],c[maxn],d[maxn];
inline bool cmp(const data &A,const data &B){
  return A.x<B.x;
}
int main(){
  int n;LL C,ans=0;
  scanf("%d%lld",&n,&C);
  for(int i=1;i<=n;i++)
    scanf("%lld%lld",&t[i].x,&t[i].v);
  sort(t+1,t+n+1,cmp);
  LL sum=0;
  for(int i=1;i<=n;i++){
    sum=sum+t[i].v;
    a[i]=max(a[i-1],sum-t[i].x);
    b[i]=max(b[i-1],sum-t[i].x*2);
  }
  sum=0;
  for(int i=n;i>0;i--){
    sum=sum+t[i].v;
    c[i]=max(c[i+1],sum-(C-t[i].x));
    d[i]=max(d[i+1],sum-(C-t[i].x)*2);
  }
  for(int i=1;i<=n;i++){
    ans=max(ans,max(a[i],c[i]));
    ans=max(ans,a[i-1]+d[i]);
    ans=max(ans,b[i-1]+c[i]);
  }
  printf("%lld",ans);
  return 0;
}
