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

const int N=100100;
typedef long long ll;
int a[N],n,S;
ll b[N];

pair<ll,int>solve(int l,int r){
	if((a[l]<S)==(a[r]<S)){
		if(a[l]<S)return make_pair(S-a[l],a[l]);
		else return make_pair(a[r]-S,a[r]);
	}
	if(b[l]>=b[r]){
		b[l]+=b[r];auto s=solve(l,r-1);
		return make_pair(s.first+a[r]-s.second,a[r]);
	}else{
		b[r]+=b[l];auto s=solve(l+1,r);
		return make_pair(s.first+s.second-a[l],a[l]);
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>S;
	for(int i=1;i<=n;++i)cin>>a[i]>>b[i];
	cout<<solve(1,n).first<<'\n';
	return 0;
}
