#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define all(v) (v).begin(),(v).end()
#define clr(t,v) memset(t,(v),sizeof(t))
template<class T1, class T2>ostream& operator<<(ostream& os, const pair<T1, T2>&a)
{
   return os << "(" << a.first << "," << a.second << ")";
}
template<class T>void pv(T a, T b)
{
   for(T i = a; i != b; ++i)
      cout << (*i) << " ";
   cout << endl;
}
template<class T>void chmin(T&a, const T&b)
{
   if(a > b)
      a = b;
}
template<class T>void chmax(T&a, const T&b)
{
   if(a < b)
      a = b;
}
 
int nxint()
{
   int x;
   scanf("%d", &x);
   return x;
}
 
ll x[100005], v[100005];
 
struct pos{
   ll b,  e, d;
   pos(int x, int y, int z):b(x), e(y), d(z){
   }
};
int main()
{
   ll n, C;
   while(cin >> n >> C) {
      rep(i, n)
         cin >> x[i] >> v[i];
      queue<pos> que;
      que.push(pos(0, n - 1, v[0] - x[0]));
      que.push(pos(n - 1, 0, v[n - 1] - C +  x[n - 1]));
      ll ans = max(v[0] - x[0], v[n - 1] - C +  x[n - 1]);
      ans = max(0, ans);
      while(!que.empty()){
         pos p = que.front();
         que.pop();
         if(p.b < p.e){
            ll t = v[p.b + 1] - x[p.b + 1] +  x[p.b];
            que.push(pos(p.b + 1, p.e,  p.d + t));
            ans = max(ans, p.d + t);
            t = v[p.e] - x[p.b] -  (C - x[p.e]);
            que.push(pos(p.e , p.b + 1,  p.d + t));
            ans = max(ans, p.d + t);
         }
         else if(p.b > p.e){
            ll t = v[p.b - 1] - x[p.b] + x[p.b -1];
            que.push(pos(p.b - 1, p.e,  p.d + t));
            ans = max(ans, p.d + t);
            t = v[p.e] - x[p.e] - ( C - x[p.b]);
            que.push(pos(p.e, p.b - 1,  p.d + t));
            ans = max(ans, p.d + t);
         }
 
      }
      cout << ans << endl;
 
 
   }
 
   return 0;
}