#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, c;
  long long int x[110000], v[110000];
  cin >> n >> c;
  for (int i = (0); i <= (n - 1); ++i) cin >> x[i] >> v[i];
  long long int y[110000], w[110000];
  for (int i = (0); i <= (n - 1); ++i) {
    y[n - 1 - i] = c - x[i];
    w[n - 1 - i] = v[i];
  }
  long long int max = 0;
  long long int ans = 0;
  long long int xmem = -1;
  for (int i = (0); i <= (n - 1); ++i) {
    ans += v[i];
    ans -= x[i];
    if (ans > max) {
      max = ans;
      xmem = i;
    }
    ans += x[i];
  }
  long long int xans = max;
  ans = 0;
  long long int ans1 = -1;
  long long int ymem = -1;
  for (int i = (0); i <= (n - 1); ++i) {
    ans += w[i];
    ans -= y[i];
    if (ans > ans1) {
      ans1 = ans;
      ymem = i;
    }
    ans += y[i];
  }
  long long int yans = ans1;
  if (max < ans1) max = ans1;
  for (int i = (0); i <= (n - 1); ++i) {
    for (int j = (0); j <= (n - 1 - i - 1); ++j) {
      ans = 0;
      for (int ii = (0); ii <= (i + 1 - 1); ++ii) ans += v[ii];
      for (int jj = (0); jj <= (j + 1 - 1); ++jj) ans += w[jj];
      ans -= x[i] * 2;
      ans -= y[j];
      if (ans > max) max = ans;
    }
  }
  for (int i = (0); i <= (n - 1); ++i) {
    for (int j = (0); j <= (n - 1 - i - 1); ++j) {
      ans = 0;
      for (int ii = (0); ii <= (i + 1 - 1); ++ii) ans += w[ii];
      for (int jj = (0); jj <= (j + 1 - 1); ++jj) ans += v[jj];
      ans -= y[i] * 2;
      ans -= x[j];
      if (ans > max) max = ans;
    }
  }
  cout << max;
  return 0;
}
