#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<pair<long long, long long> > g[100005];
long long vis[100005], dis[100005];
void dij(long long x) {
  memset(vis, 0, sizeof(vis));
  memset(dis, 0x7f, sizeof(dis));
  dis[x] = 0;
  priority_queue<pair<long long, long long> > q;
  q.push(make_pair(0, x));
  while (!q.empty()) {
    long long u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (long long i = 0; i < g[u].size(); i++) {
      long long v = g[u][i].first;
      if (vis[v]) continue;
      if (dis[u] + g[u][i].second < dis[v]) {
        dis[v] = dis[u] + g[u][i].second;
        q.push(make_pair(-dis[v], v));
      }
    }
  }
}
void solve() {
  cin >> m >> n;
  for (long long i = 1; i <= n; i++)
    g[i].push_back(make_pair(i + 1, 1)), g[i + 1].push_back(make_pair(i, 0));
  while (m--) {
    long long x, s;
    cin >> x >> s;
    long long l = max(1LL, x - s), r = min(n + 1, x + s + 1), w = 0;
    while (1) {
      g[l].push_back(make_pair(r, w));
      w++;
      if (l == 1 || r == n + 1) break;
      l--, r++;
    }
  }
  dij(1);
  cout << dis[n + 1];
}
signed main() {
  long long _ = 1;
  while (_--) solve();
  return 0;
}
