#include <bits/stdc++.h>
using namespace std;
struct Sushi {
  long x;
  long v;
  Sushi(long dis, long value) {
    x = dis;
    v = value;
  }
};
struct less_than {
  inline bool operator()(const Sushi& sushi1, const Sushi& sushi2) {
    return (sushi1.x < sushi2.x);
  }
};
int main() {
  int n;
  long c;
  map<long, long> sushi1;
  map<long, long> sushi2;
  long calc[100000] = {0};
  long cala[100000] = {0};
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    long x;
    long v;
    cin >> x;
    cin >> v;
    sushi1[x] = v;
    sushi2[c - x] = v;
  }
  map<long, long>::iterator it;
  map<long, long>::iterator it1;
  long last = 0;
  long tmp = 0;
  int i = 0;
  for (it = sushi1.begin(); it != sushi1.end(); it++) {
    tmp += it->second - (it->first - last);
    last = it->first;
    calc[i] = tmp;
    i++;
  }
  last = 0;
  tmp = 0;
  i = 0;
  for (it = sushi2.begin(); it != sushi2.end(); it++) {
    tmp += it->second - (it->first - last);
    last = it->first;
    cala[i] = tmp;
    i++;
  }
  long max = 0;
  it = sushi1.begin();
  for (int j = 0; j < n; j++) {
    tmp = calc[j];
    if (max < tmp) max = tmp;
    for (int k = 0; k < (n - j - 1); k++) {
      tmp = calc[j] - it->first + cala[k];
      if (max < tmp) max = tmp;
    }
    it++;
  }
  it = sushi2.begin();
  for (int j = 0; j < n; j++) {
    tmp = cala[j];
    if (max < tmp) max = tmp;
    for (int k = 0; k < (n - j - 1); k++) {
      tmp = cala[j] - it->first + calc[k];
      if (max < tmp) max = tmp;
    }
    it++;
  }
  cout << max << endl;
  return 0;
}
