#include<bits/stdc++.h>
const int N=100005;
using namespace std;
int n,S,a[N],lst=2;
long long b[N],ans;
bool fl;
int main(){
	scanf("%d%d",&n,&S);
	for(int i=1;i<=n;i++)
	scanf("%d%lld",a+i,b+i);
	a[n+1]=2e9;
	for(int h=1,t=n;;){
		if(a[h]<S&&a[t]>S){
			fl=b[h]<b[t];
			if(lst^fl)ans+=a[t]-a[h];
			fl?b[t]+=b[h++]:b[h]+=b[t--];
			lst=fl;
		}
		else{
			if(a[h]>S)lst?ans+=a[t]-S:0;
			if(a[t]<S)lst^1?ans+=S-a[h]:0;
			break;
		}
	}
	printf("%lld",ans);
}