#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
const int N = 200007;
int t[4 * N];
int dp[N];
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = dp[tl];
  } else {
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
int sum(int v, int tl, int tr, int l, int r) {
  if (l > r) return INT_MAX;
  if (l == tl && r == tr) {
    return t[v];
  }
  int tm = (tl + tr) / 2;
  return min(sum(v * 2, tl, tm, l, min(r, tm)),
             sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(int v, int tl, int tr, int pos, int new_val) {
  if (tl == tr) {
    t[v] = new_val;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2, tl, tm, pos, new_val);
    else
      update(v * 2 + 1, tm + 1, tr, pos, new_val);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
vector<pair<int, int> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin.tie(NULL);
  int n, m, i, j, k, ans = 0;
  cin >> n >> m;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back({x - y + m, x + y + m});
  }
  int lt = 0, rt = 2 * m + 1;
  for (int i = lt; i <= rt; i++) dp[i] = INT_MAX;
  dp[rt] = 0;
  build(1, lt, rt);
  ans = INT_MAX;
  for (int i = rt - 1; i >= lt; i--) {
    for (int j = 0; j < n; j++) {
      int l = v[j].first, r = v[j].second;
      if (l >= i) {
        int curl = min(i + 1, rt), curr = min(r + l - i + 1, rt);
        int x = sum(1, lt, rt, curl, curr);
        if (x != INT_MAX) dp[i] = min(dp[i], l - i + x);
      }
    }
    update(1, lt, rt, i, dp[i]);
    if (i <= m + 1) {
      ans = min(ans, dp[i]);
    }
  }
  cout << ans << "\n";
  return 0;
}
