#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long int pos;
  long long int cost;
  long long int left;
  long long int right;
  char dir;
  bool rev;
  bool operator<(const Node &r) const { return cost < r.cost; }
};
random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> randV(2, 1e9);
int main() {
  long long int n, c;
  cin >> n >> c;
  vector<long long int> x(n + 1);
  vector<long long int> v(n + 1);
  x[0] = v[0] = 0;
  for (auto i = 0; i < (n); i++) cin >> x[i + 1] >> v[i + 1];
  priority_queue<Node> que;
  que.push({0, 0, n, 1, 'r', false});
  que.push({0, 0, n, 1, 'l', false});
  long long int maxx = 0;
  long long int cnt = 0;
  vector<vector<vector<bool>>> visited(
      n + 1, vector<vector<bool>>(n + 1, vector<bool>(n + 1, false)));
  while (!que.empty() && cnt++ < 1e8) {
    Node node = que.top();
    que.pop();
    node.cost += v[node.pos];
    maxx = max(maxx, node.cost);
    if (node.left == 0 || node.right == 0) {
      continue;
    }
    if (node.left + 1 == node.right) {
      continue;
    }
    if (visited[node.left][node.pos][node.right]) {
      continue;
    }
    visited[node.left][node.pos][node.right] = true;
    bool rev0 = false;
    if (node.dir == 'l' && !node.rev) rev0 = true;
    if (node.dir == 'r' || rev0) {
      long long int r = node.right;
      long long int dist;
      if (node.pos < r)
        dist = x[r] - x[node.pos];
      else
        dist = (c - x[node.pos]) + x[r];
      long long int rr = r + 1;
      rr %= n + 1;
      que.push({r, node.cost - dist, node.left, rr, 'r', rev0});
    }
    bool rev1 = false;
    if (node.dir == 'r' && !node.rev) rev1 = true;
    if (node.dir == 'l' || rev1) {
      long long int l = node.left;
      long long int dist;
      if (l < node.pos)
        dist = x[node.pos] - x[l];
      else
        dist = x[node.pos] + (c - x[l]);
      long long int long long int = l - 1;
      if (long long int < 0) long long int += n + 1;
      que.push({l, node.cost - dist, long long int, node.right, 'l', rev1});
    }
  }
  cout << maxx << endl;
  return 0;
}
