#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=1e5+5;
ll n,st,x[N],p[N];
ll calc(ll l,ll r,ll t){
	if(st<x[l])return x[r]-st;if(x[r]<st)return st-x[l];
	if(p[l]>=p[r])return p[l]+=p[r],calc(l,r-1,l)+(t==r?x[r]-x[l]:0);
	else return p[r]+=p[l],calc(l+1,r,r)+(t==l?x[r]-x[l]:0);
}
signed main(){
	n=read(),st=read();
	for(ll i=1;i<=n;i++)x[i]=read(),p[i]=read();
	return cout<<calc(1,n,p[1]<p[n]?1:n),signed();
}
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

using ll = long long;

int main() {
    int N;
    ll S;
    cin >> N >> S;

    ll X[N], P[N];
    for (int i = 0; i < N; ++i) {
        cin >> X[i] >> P[i];
    }

    queue<ll> neg, pos;
    // Sより前、後にある座標をそれぞれ両端から入れていく
    for (int i = 0; i < N && X[i] < S; ++i) {
        neg.push(P[i]);
    }
    for (int i = N - 1; i >= 0 && X[i] > S; --i) {
        pos.push(P[i]);
    }

    vector<ll> route;
    // 最適解における探索順を後ろから

    int l = 0, r = N - 1;
    while (true) {
        // もう一方しか残っていない場合
        if (neg.empty()) {
            for (; l <= r; --r) {
                route.push_back(r);
            }
            break;
        }
        if (pos.empty()) {
            for (; l <= r; ++l) {
                route.push_back(l);
            }
            break;
        }

        // 末端の人口を比較、少ない方が選ばれる
        if (neg.front() >= pos.front()) {
            route.push_back(r);
            --r;
            neg.front() += pos.front();
            pos.pop();
        } else {
            route.push_back(l);
            ++l;
            pos.front() += neg.front();
            neg.pop();
        }
    }

    ll ans = 0, now = S;
    while (!route.empty()) {
        ll id = route.back();
        route.pop_back();
        ans += abs(X[id] - now);
        now = X[id];
    }

    cout << ans << endl;
    return 0;
}
