#include <bits/stdc++.h>
#include <cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<ll> sll;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))

// constexpr int INF = 1<<25;
constexpr ll  INF = 1LL<<50;
// int dp[N_MAX][M_MAX] = {}

// Forward declaration
template <typename T>
void dumpContents(const T& v, const string& msg="");

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

/*
 * Segment Tree.
 *
 *  n=4
 *     [      0      ]
 *     [  1  ] [  2  ]
 *     [3] [4] [5] [6]
 *     (0) (1) (2) (3)
 *
 *     - MAX_N
 *     - Comparator: std::less or std::greaterr
 */
template<int MAX_N>
class SegmentTree {
private:
    int n;
    vector<ll> dat;

    // Find a minimum in [a,b).
    // A node k corresponds to a range [l,r) in the segment tree.
    // So, the initial query should be query(a, b, 0, 0, n)
    ll query(const int a, const int b, const int k, const int l, const int r) {
        // 1) No cross between [a,b) and [l, r)
        if (r<=a || b<=l) return -INF;

        // 2) [a,b) includes [l ,r)
        if (a <= l && r <= b) return dat[k];

        // 3) otherwise
        const ll vl = query(a, b, k*2+1, l, (l+r)/2);
        const ll vr = query(a, b, k*2+2, (l+r)/2, r);
        return max({vl, vr});
    }

public:
    SegmentTree(int n_) {
        // Set n to power of 2
        n = 1;
        while (n < n_) n *= 2;

	dat.resize(2*n-1);
	fill(dat.begin(), dat.end(), -INF);
    }

    // Update the value of the k-th node (zero indexed) to a.
    void update(int k, ll a) {
        k += n - 1;
        dat[k] = a;
        // Climbing up the tree
        while (k>0) {
	    k = (k-1)/2;
	    dat[k] = max({dat[k*2+1], dat[k*2+2]});
        }
    }

    ll query(const int a, const int b) {
        return query(a, b, 0, 0, n);
    }

};

constexpr int N_MAX=1e5+2;
int N;
ll C;
vll X;
vll V;

ll solve() {
  vll toLeft(N+2);
  SegmentTree<N_MAX> toRight(N+2);

  for (int i=1; i<=N+1; i++) {
    toLeft[i] = toLeft[i-1] + V[i] - (X[i] - X[i-1]);
  }

  ll tmp = 0;
  toRight.update(N+1, 0);
  for (int i=N; i>=0; i--) {
    tmp += V[i] - (X[i+1] - X[i]);
    toRight.update(i, tmp);
  }

  vll ret;
  for (int i=0; i<=N; i++) {
    ll tmp = toRight.query(i+1, N+1) - X[i];
    ret.emplace_back(toLeft[i] + max({0ll, tmp}));
  }

  return *max_element(begin(ret), end(ret));
}

int main(int argc, char** argv) {
  cin >> N >> C;
  X.resize(N+1+1);
  V.resize(N+1+1);
  X[0] = 0; // dummy
  V[0] = 0;
  X[N+1] = C;
  V[N+1] = 0;
  for (int i=1; i<=N; i++) {
    cin >> X[i] >> V[i];
  }
  ll retA = solve();

  reverse(begin(V), end(V));
  reverse(begin(X), end(X));
  for (int i=0; i<int(X.size()); i++) {
    X[i] = C-X[i];
  }
  ll retB = solve();
  cout << max({retA, retB}) << endl;

  return 0;
}


Measured memory_bytes: 6480