#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int nmax = 5e4 + 5;
int l[nmax], r[nmax];
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", l + i, r + i);
  }
  long long res = 0;
  for (int i = 0; i < n;) {
    if (!(l[i] <= x && r[i] >= x)) {
      int lc = 0, rc = 0;
      int lc2 = 0, rc2 = 0;
      int j = i;
      while ((lc < 1 || rc < 1) && lc2 < 2 && rc2 < 2) {
        if (r[j] <= x) ++lc;
        if (l[j] >= x) ++rc;
        if (r[j] < x) ++lc2;
        if (l[j] > x) ++rc2;
        ++j;
      }
      if (lc && rc) {
        if (l[i] > x) {
          res += l[i] - x;
        }
        if (r[i] < x) {
          res += x - r[i];
        }
        ++i;
      } else if (lc2 == 2) {
        int nxt = 0;
        for (int k = i; k < j; ++k) {
          nxt = max(nxt, l[k]);
          if (r[k] < x) {
            nxt = max(nxt, r[k]);
          }
        }
        res += x - nxt;
        x = nxt;
      } else if (rc2 == 2) {
        int nxt = mod;
        for (int k = i; k < j; ++k) {
          nxt = min(nxt, r[k]);
          if (l[k] > x) {
            nxt = min(nxt, l[k]);
          }
        }
        res += nxt - x;
        x = nxt;
      }
    } else {
      ++i;
    }
  }
  printf("%lld\n", res);
  return 0;
}
