#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
#define N 120000

LL n,m,a[N],b[N],ans,x,lst;

void renew(int x){
	if (!lst){lst=x; return;}
	ans+=abs(a[x]-a[lst]);
	lst=x;
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=n;++i) scanf("%lld%lld",a+i,b+i);
	for (int i=1,j=n;i<=j;){
		if (a[j]<m){renew(i); ++i;}
		else{
			if (a[i]>m){renew(j); --j;}
			else{
				if (b[i]>=b[j]){
					renew(j); b[i]+=b[j]; --j;
				}
				else{
					renew(i); b[j]+=b[i]; ++i;
				}
			}
		}
	}
	ans+=abs(a[lst]-m);
	printf("%lld\n",ans);
	
	return 0;
}
			