#include <bits/stdc++.h>
using namespace std;
int n, c;
struct Sushi {
  int x;
  int v;
};
int search(vector<Sushi> sushis, int x0) {
  if (sushis.size() == 0) {
    return 0;
  }
  auto s = sushis[0];
  int x1 = s.x;
  int v1 = s.v;
  int d1 = (x1 > x0) ? (x1 - x0) : (x1 + c - x0);
  vector<Sushi> next1(sushis.size() - 1);
  for (int i = 0; i < sushis.size() - 1; i++) {
    next1[i] = sushis[i + 1];
  }
  int a = (v1 - d1) + search(next1, x1);
  auto s2 = sushis[sushis.size() - 1];
  int x2 = s2.x;
  int v2 = s2.v;
  int d2 = (x2 > x0) ? (x0 + c - x2) : (x0 - x2);
  vector<Sushi> next2(sushis.size() - 1);
  for (int i = 0; i < sushis.size() - 1; i++) {
    next2[i] = sushis[i];
  }
  int b = (v2 - d2) + search(next2, x2);
  return max(a, max(b, 0));
}
int main() {
  cin >> n >> c;
  vector<Sushi> sushis(n);
  for (int i = 0; i < n; i++) {
    cin >> sushis[i].x;
    cin >> sushis[i].v;
  }
  cout << search(sushis, 0) << endl;
  return 0;
}
