
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n;
	cin>>n;
	ll S; cin>>S;
	ll x[n], p[n];
	f(i,0,n) cin>>x[i]>>p[i];
	ll ans = 0;
	function<int(int,int)> dfs = [&](int i, int j) {
		if (x[i]>S) {ans += x[j]-S; return j;}
		else if (x[j]<S) {  ans += S-x[i]; return i; }
		else {
			if (p[i]>=p[j]) {
				p[i] += p[j];
				ans += x[j]-x[dfs(i,j-1)];
				return j;
			} else {
				p[j] += p[i];
				ans += x[dfs(i+1,j)]-x[i];
				return i;
			}
		}
	};
	dfs(0,n-1);
	cout << ans << endl;
		

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}

