#include <bits/stdc++.h>

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N; int64_t S; cin >> N >> S;
   vector<int64_t> X(N), P(N);
   for (int i = 0; i < N; ++i) cin >> X[i] >> P[i];
   int64_t ans = 0;
   auto go = [&](int64_t X) {
      ans += abs(X - S);
      S = X;
   };
   function<void(int, int)> solve = [&](int l, int r) {
      if (X[l] > S) return go(X[r]);
      if (X[r] < S) return go(X[l]);
      if (P[l] >= P[r]) {
         P[l] += P[r];
         solve(l, r-1);
         return go(X[r]);
      } else {
         P[r] += P[l];
         solve(l+1, r);
         return go(X[l]);
      }
   };
   solve(0, N-1);
   cout << ans << '\n';
   return 0;
}
