#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9;
int bit[N];
int get(int i) {
  int v = inf;
  for (; i; i -= i & -i) v = min(v, bit[i]);
  return v;
}
void put(int i, int v) {
  for (; i < N && v < bit[i]; i += i & -i) bit[i] = v;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v(n);
  for (auto &[x, y] : v) cin >> x >> y;
  sort(begin(v), end(v));
  fill(begin(bit), end(bit), inf);
  put(m + 1, 0);
  for (auto [x, y] : v) {
    for (int c = 0; y + c <= m; c++) {
      int d = y + c;
      int l = max(1, x - d);
      int r = min(m, x + d) + 1;
      int v = get(m + 2 - l);
      put(m + 2 - r, v + c);
    }
  }
  cout << get(1) << '\n';
}
