#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
long long N, C;
long long X[100000], V[100000];
int main() {
  cin >> N >> C;
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> V[i];
  }
  long long M = 0;
  for (int i = 0; i < 1 << N; i++) {
    long long col = 0;
    bool ST = true;
    long long s, l;
    vector<long long> v, u;
    for (int j = 0; j < N; j++) {
      if (i >> j & 1) {
        col += V[j];
        if (ST) {
          s = X[j];
          ST = false;
        }
        l = X[j];
        v.push_back(X[j]);
        u.push_back(C - X[j]);
      }
    }
    if (ST) {
      continue;
    } else if (s == l) {
      M = max(M, col - min(s, C - s));
      continue;
    }
    long long co = min(l, C - s);
    for (int i = 0; i < (int)v.size() - 1; i++) {
      co = min(co, v[i] + C - (v[i + 1] - v[i]));
    }
    reverse(u.begin(), u.end());
    for (int i = 0; i < (int)u.size() - 1; i++) {
      co = min(co, u[i] + C - (u[i + 1] - u[i]));
    }
    col -= co;
    M = max(M, col);
  }
  cout << M << endl;
  return 0;
}
