#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n;
  LL c;
  cin >> n >> c;
  vector<LL> sp(n), rsp(n);
  vector<LL> sv(n);
  REP(i,n) cin >> sp[i] >> sv[i];
  REP(i,n) rsp[i] = c - sp[i];
  LL answer = 0ll;
  vector<LL> ssv(sv), rssv(sv);
  REP(i, n-1) ssv[i+1] += ssv[i];
  for(int i = n-1; i>0; --i) rssv[i-1] += rssv[i];
  REP(i, n) ssv[i] -= sp[i];
  REP(i, n) rssv[i] -= rsp[i];
  REP(i, n-1) ssv[i+1] = max(ssv[i+1], ssv[i]);
  for(int i = n-1; i>0; --i) rssv[i-1] = max(rssv[i-1], rssv[i]);
  answer = max(answer, ssv[n-1]);
  REP(i, n-1) answer = max(answer, ssv[i] - sp[i] + rssv[i+1]);
  answer = max(answer, rssv[0]);
  for(int i = n-1; i>1; --i) answer = max(answer, rssv[i] - rsp[i] + ssv[i-1]);
  cout << answer << endl;
  return 0;
}
