#include <bits/stdc++.h>
using namespace std;
int N, X;
signed long long L[5050], R[5050];
signed long long CL, CR;
signed long long tot;
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> X;
  CL = CR = X;
  for (i = 0; i < N; i++) {
    cin >> L[i] >> R[i];
    if (CR <= L[i]) {
      tot += L[i] - CR;
      CL = CR;
      CR = L[i];
    } else if (R[i] <= CL) {
      tot += CL - R[i];
      CR = CL;
      CL = R[i];
    } else {
      CL = max(CL, L[i]);
      CR = min(CR, R[i]);
    }
  }
  cout << tot << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false);
  for (i = 0; i < argc - 1; i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
