#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e18;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
int main() {
  ios::sync_with_stdio(false);
  int N;
  long long C;
  cin >> N >> C;
  vector<pair<long long, long long> > sushi(N);
  map<int, pair<long long, long long> > sushi_l, sushi_r;
  for (int i = 0; i < (int)(N); i++) {
    cin >> sushi[i].first >> sushi[i].second;
  }
  assert(N <= 100);
  sushi_l[0] = pair<long long, long long>(C, 0);
  sushi_r[0] = pair<long long, long long>(0, 0);
  for (int i = 0; i < (int)(N); i++) {
    sushi_l[(i + 1)] = sushi[N - i - 1];
    sushi_r[(i + 1)] = sushi[i];
  }
  long long ans = 0LL;
  vector<long long> mx_r(N + 1);
  long long sumr = 0;
  for (int r = 0; r < N; r++) {
    sumr += sushi_r[r + 1].second;
    ans = max(ans, sumr - sushi_r[r + 1].first);
    mx_r[r + 1] = sumr - sushi_r[r + 1].first;
    mx_r[r + 1] = max(mx_r[r + 1], mx_r[r]);
  }
  vector<long long> mx_l(N + 1);
  long long suml = 0;
  for (int l = 0; l < N; l++) {
    suml += sushi_l[l + 1].second;
    ans = max(ans, suml - (C - sushi_l[l + 1].first));
    mx_l[l + 1] = suml - (C - sushi_l[l + 1].first);
    mx_l[l + 1] = max(mx_l[l + 1], mx_l[l]);
  }
  suml = 0;
  for (int l = 0; l < N; l++) {
    suml += sushi_l[l + 1].second;
    long long tmp = suml - 2 * (C - sushi_l[l + 1].first) + mx_r[N - l - 1];
    ans = max(ans, tmp);
    cerr << "("
         << "l"
         << ", "
         << "tmp"
         << ") = (" << l << ", " << tmp << ")" << endl;
  }
  sumr = 0;
  for (int r = 0; r < N; r++) {
    sumr += sushi_r[r + 1].second;
    long long tmp = sumr - 2 * sushi_r[r + 1].first + mx_l[N - r - 1];
    ans = max(ans, tmp);
    cerr << "("
         << "r"
         << ", "
         << "tmp"
         << ") = (" << r << ", " << tmp << ")" << endl;
  }
  cout << ans << endl;
}
