#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
long long n,m,i,j,p[100005],c[100005],s[100005],ans,r,lst;
int main(){
	cin>>n>>m;
	rep(i,n){
		cin>>p[i]>>c[i];
		if(p[i]<=m) r=i;
	}
	i=1;j=n;lst=0;
	while(i<=r&&j>r){
		if(c[i]>=c[j]){
			if(lst!=1){
				lst=1;
				s[i]+=p[j]-p[i];
			}
			c[i]+=c[j];
			s[i]+=s[j];
			j--;
		}
		else{
			if(lst!=-1){
				lst=-1;
				s[j]+=p[j]-p[i];
			}
			c[j]+=c[i];
			s[j]+=s[i];
			i++;
		}
	}
	if(i<=r) ans=s[i]+m-p[i]; else ans=s[j]+p[j]-m;
	cout<<ans<<endl;
	return 0;
}