#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, start;
  cin >> n >> start;
  vector<long long> pos;
  pos.push_back(start);
  long long x[n], y[n];
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    pos.push_back(x[i]);
    pos.push_back(y[i]);
  }
  sort(pos.begin(), pos.end());
  long long len = pos.size();
  long long cost[len];
  for (long long i = 0; i < len; i++) {
    cost[i] = abs(pos[i] - start);
  }
  long long new_cost[len];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < len; j++) {
      new_cost[j] = cost[j] + (pos[j] < x[i] ? (x[i] - pos[j]) : 0) +
                    (pos[j] > y[i] ? (pos[j] - y[i]) : 0);
    }
    for (long long j = 0; j + 1 < len; j++) {
      if (pos[j] < x[i] && new_cost[j] < new_cost[j + 1]) {
        new_cost[j + 1] = new_cost[j];
      }
    }
    for (long long j = len - 1; j >= 0; j--) {
      if (y[i] < pos[j] && new_cost[j] < new_cost[j - 1]) {
        new_cost[j - 1] = new_cost[j];
      }
    }
    for (long long j = 0; j < len; j++) cost[j] = new_cost[j];
  }
  long long ans = cost[0];
  for (long long i = 0; i < len; i++) {
    ans = min(ans, cost[i]);
  }
  cout << ans << '\n';
  return 0;
}
