#include <bits/stdc++.h>
using namespace std;
class D {
 public:
  int n;
  long long c;
  vector<long long> x;
  vector<long long> v;
  void input() {
    cin >> n >> c;
    x.resize(n);
    v.resize(n);
    for (int i = 0; i < n; ++i) {
      cin >> x[i];
      cin >> v[i];
    }
  }
  long long solve(int i, long long pos, long long score, long long cost) {
    if (i == n) return score - cost;
    long long bns = solve(i + 1, pos, score, cost);
    long long d = abs(x[i] - pos);
    long long ans =
        solve(i + 1, x[i], score + v[i], cost + ((d <= c - d) ? d : (c - d)));
    return ((bns < ans) ? ans : bns);
  }
};
int main() {
  D d;
  d.input();
  cout << d.solve(0, 0, 0, 0) << endl;
  return 0;
}
