#include <bits/stdc++.h>
using namespace std;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}
int maxrighti = -1;
__int128 right(int N, long long C, vector<pair<long long, long long>> &X) {
  __int128 res = 0;
  __int128 sum = 0;
  for (int i = 0; i < (N); ++i) {
    __int128 x = X[i].first, cal = X[i].second;
    sum += cal;
    if (res < sum - x) {
      res = sum - x;
      maxrighti = i;
    }
  }
  return res;
}
int maxlefti = -1;
__int128 left(int N, long long C, vector<pair<long long, long long>> &X) {
  __int128 res = 0;
  __int128 sum = 0;
  for (int i = N - 1; i >= 0; --i) {
    __int128 x = C - X[i].first, cal = X[i].second;
    sum += cal;
    if (res < sum - x) {
      res = sum - x;
      maxlefti = i;
    }
  }
  return res;
}
__int128 solve(int N, long long C, vector<pair<long long, long long>> &X) {
  __int128 res = 0;
  __int128 rmax = right(N, C, X);
  __int128 lmax = left(N, C, X);
  if (res < rmax) res = rmax;
  if (res < lmax) res = lmax;
  __int128 lsum = 0;
  for (int l = 0; l < (N); ++l) {
    __int128 lx = X[l].first, lcal = X[l].second;
    lsum += lcal;
    __int128 rsum = 0;
    for (int r = N - 1; r > l; --r) {
      __int128 rx = C - X[r].first, rcal = X[r].second;
      rsum += rcal;
      __int128 a = lsum - 2 * lx + rsum - rx;
      if (a > res) res = a;
      __int128 b = rsum - 2 * rx + lsum - lx;
      if (b > res) res = b;
    }
  }
  return res;
}
int main() {
  long long N, C;
  vector<pair<long long, long long>> X;
  cin >> N >> C;
  for (int i = 0; i < (N); ++i) {
    long long x, v;
    cin >> x >> v;
    X.emplace_back(x, v);
  }
  cout << solve(N, C, X) << endl;
  return 0;
}
