#include <bits/stdc++.h>
using namespace std;
clock_t __START, __END;
double __TOTALTIME;
void _MS() { __START = clock(); }
void _ME() {
  __END = clock();
  __TOTALTIME = (double)(__END - __START) / CLOCKS_PER_SEC;
  cout << "Time: " << __TOTALTIME << " s" << endl;
}
const double E = 2.718281828;
const double PI = acos(-1.0);
const long long INF = (1LL << 60);
const int inf = (1 << 30);
const double ESP = 1e-9;
const int mod = (int)1e9 + 7;
const int N = (int)5e3 + 10;
int main() {
  int n, pos;
  scanf("%d%d", &n, &pos);
  int l = pos, r = pos;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int nowl, nowr;
    scanf("%d%d", &nowl, &nowr);
    if (l <= nowl && nowr <= r)
      l = nowl, r = nowr;
    else if (nowl > r)
      ans += abs(nowl - r), l = r, r = nowl;
    else if (nowr < l)
      ans += abs(nowr - l), r = l, l = nowr;
    else
      l = max(l, nowl), r = min(r, nowr);
  }
  printf("%lld\n", ans);
  return 0;
}
