#include <bits/stdc++.h>
using namespace std;
long long maxn = -1;
long long n, C;
long long x[110000], v[110000];
bool vis[110000];
long long min3(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
void dfs(int now, long long sum) {
  maxn = max(maxn, sum);
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    vis[i] = true;
    long long lj = min3(fabs(x[now] - x[i]), fabs(C - x[now]) + x[i],
                        fabs(C - x[i]) + x[now]);
    dfs(i, sum - lj + v[i]);
    vis[i] = false;
  }
}
int main() {
  cin >> n >> C;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
  }
  dfs(0, 0);
  cout << maxn;
  return 0;
}
