#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int N;
// a：時計回り　ｂ：反時計回り
ll C,X[101010],V[101010],a[101010],b[101010];

int main(){
  cin>>N>>C;
  ll ans=0;
  rep(i,N) cin>>X[i+1]>>V[i+1];

  rep(i,N) a[i+1]=a[i]+V[i+1]-(X[i+1]-X[i]);
  rep(i,N) a[i+1]=max(a[i+1],a[i]);

  X[N+1]=C;
  for(int i=N;i>=0;i--) b[i]=b[i+1]+V[i]-(X[i+1]-X[i]);
  for(int i=N;i>=0;i--) b[i]=max(b[i],b[i+1]);

  for(int i=1;i<=N;i++){
    ans=max(ans,a[i]);
    ans=max(ans,b[i]);
    ans=max(ans,a[i]+b[i+1]-min(X[i],(C-X[i+1])));
  }
  cout<<ans<<endl;
  return 0;
}
