#include <bits/stdc++.h>
const int INF = 1e9;
const long long lINF = 1e18;
const double EPS = 1e-12;
using namespace std;
const int MOD = 1e9 + 7;
int n;
int l[5555], r[5555];
int x;
int main() {
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", l + i, r + i);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (l[i] > x) {
      vector<int> v;
      int mn = INF;
      for (int j = i; j < n; j++) {
        mn = min(mn, r[j]);
        if (l[j] > x) {
          v.push_back(min(l[j], mn));
        }
      }
      sort((v).begin(), (v).end());
      if (v.size() >= 2) {
        v[v.size() - 2] = max(v[v.size() - 2], x);
        ans += abs(v[v.size() - 2] - x);
        x = v[v.size() - 2];
      }
      if (x < l[i]) {
        ans += l[i] - x;
      }
      if (x > r[i]) {
        ans += x - r[i];
      }
    } else if (r[i] < x) {
      vector<int> v;
      int mx = -INF;
      for (int j = i; j < n; j++) {
        mx = max(mx, l[j]);
        if (r[j] < x) {
          v.push_back(max(r[j], mx));
        }
      }
      sort((v).begin(), (v).end());
      reverse((v).begin(), (v).end());
      if (v.size() >= 2) {
        v[v.size() - 2] = min(v[v.size() - 2], x);
        ans += abs(v[v.size() - 2] - x);
        x = v[v.size() - 2];
      }
      if (x < l[i]) {
        ans += l[i] - x;
      }
      if (x > r[i]) {
        ans += x - r[i];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
