#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int n;
long long c;
vector<pair<long long, long long> > x;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    long long tempx, tempv;
    cin >> tempx >> tempv;
    x.push_back(make_pair(tempx, tempv));
  }
  vector<long long> sumr, suml, sumbr, sumbl;
  sumr.push_back(0);
  suml.push_back(0);
  sumbr.push_back(0);
  sumbl.push_back(0);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    sumr.push_back(sumr[i] + x[i].second);
    ans = max(ans, sumr[i + 1] - x[i].first);
    sumbr.push_back(max(sumbr[i], sumr[i + 1] - 2 * x[i].first));
  }
  for (int i = 0; i < n; i++) {
    suml.push_back(suml[i] + x[n - 1 - i].second);
    ans = max(ans, suml[i + 1] - (c - x[n - 1 - i].first));
    sumbl.push_back(max(sumbl[i], suml[i + 1] - 2 * (c - x[n - 1 - i].first)));
  }
  for (int i = 1; i < n; i++) {
    ans = max(ans, sumr[i] - x[i - 1].first + sumbl[n - i - 1]);
  }
  for (int i = 1; i < n; i++) {
    ans = max(ans, suml[i] - (c - x[n - i].first) + sumbr[n - i - 1]);
  }
  cout << ans << "\n";
}
