#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++) {
    deque<pair<long long, long long> > eat;
    for (int j = 0; j < N; j++) {
      if (i >> j & 1) {
        eat.push_back(make_pair(X[j], V[j]));
      }
    }
    long long col = 0;
    long long now = 0;
    while (!eat.empty()) {
      pair<long long, long long> L = eat.front(), R = eat.back();
      long long ll = min(abs(L.first - now), C - abs(L.first - now));
      long long lr = min(abs(R.first - now), C - abs(R.first - now));
      if (ll < lr) {
        col += L.second - ll;
        now = L.first;
        eat.pop_front();
      } else {
        col += R.second - lr;
        now = R.first;
        eat.pop_back();
      }
    }
    M = max(M, col);
  }
  cout << M << endl;
  return 0;
}
