#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
  int i,N,c;//num,circle
  cin>>N>>c;
  int x[N],cal[N];//x:distance

  for(i=0;i<N;i++){
    cin>>x[i]>>cal[i];
  }

  int mx[N+1]={0};
  int mx2[N+1]={0};
  int ans,s;
  
  //clockwise
  for(i=N-1;i>=0;i--){
    s+=cal[i];//consumed calories
    mx[i] = max(mx[i+1],s-(c-x[i]));//c-x[i]: used calories
    mx2[i] = max(mx2[i+1],s-(c-x[i])*2);//return first point
  }
  ans = max(mx[0],mx2[0]);
  s=0;//initialize calories

  //anticlockwise
  for(i=0;i<N;i++){
    s+=cal[i];
    ans = max(ans, s-x[i]*2 + mx[i+1]);//return first point 
    ans = max(ans, s-x[i] + mx2[i+1]);
  }
  cout << ans << endl;
  return 0;
}
