#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PI;
const LL N=100005;
LL n,S;
LL x[N],p[N];
vector<PI> vec[N];
void link (LL x,LL y,LL c)	{vec[x].push_back({y,c});}
LL ans[N];
void dfs (LL x)
{
	LL siz=vec[x].size();
	for (LL u=0;u<siz;u++)
	{
		LL y=vec[x][u].first,z=vec[x][u].second;
		ans[y]=ans[x]+z;
		dfs(y);
	}
}
int main()
{
	scanf("%lld%lld",&n,&S);
	for (LL u=1;u<=n;u++)	scanf("%lld%lld",&x[u],&p[u]);
	LL l=1,r=n;
	while (l<r)
	{	
		//printf("YES:%lld %lld\n",l,r);
		if (x[l]>=S)	{link(l,l+1,x[l+1]-x[l]);l++;}
		else if (x[r]<=S)	{link(r,r-1,x[r]-x[r-1]);r--;}
		else if (p[l]>=p[r]) {link(l,r,x[r]-x[l]);p[l]+=p[r];r--;}
		else {link(r,l,x[r]-x[l]);p[r]+=p[l];l++;}
	}
	ans[l]=abs(x[l]-S);
	dfs(l);
	printf("%lld\n",max(ans[1],ans[n]));
	return 0;
}