#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

const ll mod=1000000007;
const ll inf=1000000000000; 

#define rep(i,m,n) for(ll i=m;i<n;i++)


ll n,c;
vll x,v;

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);

  cin >> n >> c;
  x.resize(n);
  v.resize(n);
  
  rep(i,0,n) cin >> x[i] >> v[i];
  
  vll fa(n+1,0),fb(n+1,0);
  rep(i,0,n) {
    fa[i+1]=fa[i]+v[i];
    fb[i+1]=fb[i]+v[n-1-i];
  }
  rep(i,0,n) {
    fa[i+1]-=x[i];
    fb[i+1]-=(c-x[n-1-i]);
  }
  
  vll ga(n+1),gb(n+1);
  ga=fa;
  gb=fb;
  rep(i,0,n){
    ga[i+1]-=x[i];
    gb[i+1]-=(c-x[n-1-i]);
  }
  rep(i,0,n){
   fa[i+1]=max(fa[i+1],fa[i]);
   fb[i+1]=max(fb[i+1],fb[i]); 
   ga[i+1]=max(ga[i+1],ga[i]); 
   gb[i+1]=max(gb[i+1],gb[i]);  
  }
  
  
  ll res=0;
  rep(b,0,n+1){
    res=max({res,gb[b]+fa[n-b],fb[b]+ga[n-b]});    
  }
  cout << res << endl;
  
  
 
  
}