#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, s, a[N], p[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int calc(int l, int r, int x)
{
	if(s < a[l]) return a[r] - s;
	if(s > a[r]) return s - a[l];
	if(p[l] >= p[r]) return p[l] += p[r], calc(l, r - 1, l) + (x == r ? a[r] - a[l] : 0);
	else return p[r] += p[l], calc(l + 1, r, r) + (x == l ? a[r] - a[l] : 0);
}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); s = read();
	for(int i = 1; i <= n; i ++) a[i] = read(), p[i] = read();
	printf("%lld\n", calc(1, n, p[1] < p[n] ? 1 : n));
	fclose(stdin);
	fclose(stdout);
	return 0;
}
