#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e17;
const int N = 10100;
int n;
long long x[N];
long long dp[2][N];
long long a[N][2];
long long S;
int m;
void read() {
  scanf("%d%lld", &n, &S);
  for (int i = 0; i < n; i++) scanf("%lld%lld", &a[i][0], &a[i][1]);
  m = 0;
  x[m++] = S;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2; j++) x[m++] = a[i][j];
  sort(x, x + m);
  m = unique(x, x + m) - x;
  for (int i = 0; i < m; i++) dp[0][i] = INF;
  for (int i = 0; i < m; i++)
    if (x[i] == S) dp[0][i] = 0;
}
long long getDist(long long y, long long l, long long r) {
  if (y < l) return l - y;
  if (y > r) return y - r;
  return 0;
}
int main() {
  read();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) dp[1][j] = INF;
    long long val = INF;
    for (int j = 0; j < m; j++) {
      if (dp[0][j] != INF) val = min(val, dp[0][j] - x[j]);
      dp[1][j] = min(dp[1][j], val + x[j]);
    }
    val = INF;
    for (int j = m - 1; j >= 0; j--) {
      if (dp[0][j] != INF) val = min(val, dp[0][j] + x[j]);
      dp[1][j] = min(dp[1][j], val - x[j]);
    }
    for (int j = 0; j < m; j++)
      dp[0][j] = dp[1][j] + getDist(x[j], a[i][0], a[i][1]);
  }
  long long ans = INF;
  for (int i = 0; i < m; i++) ans = min(ans, dp[0][i]);
  printf("%lld\n", ans);
  return 0;
}
