#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int N, S;
vector<pii> P, Q;
vector<int> sol;

int main() {
    scanf("%d %d", &N, &S);

    for(int i = 0; i < N; i++) {
        int x, p; scanf("%d %d", &x, &p);
        if(x < S) P.push_back({x, p});
        else Q.push_back({x, p});
    }
    reverse(Q.begin(), Q.end());

    if(P.size() == 0) {
        printf("%d", Q[0].first - S);
        return 0;
    }
    if(Q.size() == 0) {
        printf("%d", S - P[0].first);
        return 0;
    }

    int pos1 = 1, pos2 = 1, dir = (P[0].second < Q[0].second);
    ll sum = 0;
    sol.push_back(P[0].first);
    sol.push_back(Q[0].first);
    sum += P[0].second + Q[0].second;
    if(P[0].second >= Q[0].second) swap(sol[0], sol[1]);
    while(1) {
        if(dir) {
            while(pos1 < P.size() && sum > P[pos1].second) {
                sum += P[pos1++].second;
            }
            if(pos1 < P.size() && sum <= P[pos1].second) {
                sol.push_back(P[pos1].first);
                sum += P[pos1].second;
                pos1++;
                dir ^= 1;
            }
            else break;
        }
        else {
            while(pos2 < Q.size() && sum >= Q[pos2].second) {
                sum += Q[pos2++].second;
            }
            if(pos2 < Q.size() && sum < Q[pos2].second) {
                sol.push_back(Q[pos2].first);
                sum += Q[pos2].second;
                pos2++;
                dir ^= 1;
            }
            else break;
        }
    }
    sol.push_back(S);

    ll ans = 0;
    for(int i = 0; i < (int)sol.size() - 1; i++) {
        ans += abs(sol[i] - sol[i + 1]);
    }
    printf("%lld", ans);
}

#include <iostream>
using namespace std; 
long long p[100001],x[100001],ans=0;
int n,s,l,r;
int main(){
	cin>>n>>s;
	for (int i=1;i<=n;i++)
		cin>>x[i]>>p[i];
	l=1;r=n;
	while (l<=r){
	if (s<=x[l]){
		cout<<x[r]-s+ans;
		return 0;
	} 
	else if (s>=x[r]){
		cout<<ans+s-x[l];
		return 0;
	}  //所有住处都在s的一侧，可以直接开过去 		
	if (p[l]>=p[r]){
		ans+=x[r]-x[l];
		while (l<r&&p[l]>=p[r]) p[l]+=p[r--];
	}
	else{
		ans+=x[r]-x[l];
		while (l<r&&p[l]<p[r]) p[r]+=p[l++];
	}
	}
	return 0;
} 