#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
int n;
ll c;
ll x[100010];
ll v[100010];
ll vsumcw[100010];
ll vsumccw[100010];

int main(){ _;
  cin>>n>>c;
  REP(i,n)cin>>x[i+1]>>v[i+1];
  x[n+1]=c;
  v[n+1]=0;
  vsumcw[0]=0;
  vsumccw[n+1]=0;
  for(int i=1;i<=n;i++){
    vsumcw[i]=v[i]+vsumcw[i-1];
  }
  for(int i=n;i>0;i--){
    vsumccw[i]=v[i]+vsumccw[i+1];
  }
  ll result=0;
  for(int i=0;i<=n;i++){
    for(int j=n+1;j>i;j--){
      ll cal=vsumcw[i]+vsumccw[j]-x[i]-(c-x[j])-min(x[i],c-x[j]);
      result=max(result,cal);
      //      cout<<i<<" "<<j<<" "<<cal<<endl;
    }
  }
  cout<<result<<endl;
}
