#include <stdio.h>
#include <limits.h>
#include <algorithm>
 
using namespace std;
 
long long int sum = 0;
 
 
void merge(int A[],int left,int mid, int right){
    int a1 = mid - left;
    int a2 = right - mid;
    int l[a1+1],r[a2+1];
    for(int i = 0; i < a1; i++) l[i] = A[left + i];
    for(int i = 0; i < a2; i++) r[i] = A[mid + i];
    l[a1] = r[a2] =  INT_MAX;
 
    int i = 0, j = 0;
    for(int k = left;k < right; k++){
        if(l[i] < r[j]){
            A[k] = l[i++];
        }else{
            A[k] = r[j++];
            sum += a1 - i;
        }
    }
}
 
void mergeSort(int A[],int left,int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}
 
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    mergeSort(A,0,n);
 
    printf("%lld\n",sum);
 
}

#include <bits/stdc++.h>

typedef long long LL;
typedef unsigned long long ULL;
#define int long long
#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') bo = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		res = (res << 1) + (res << 3) + ch - '0';
		ch = getchar();
	}
	return bo * res;
}

template <typename T>
void read(T &x) {
	x = read();
}

template <typename T, typename... Argv>
void read(T &a, Argv &... argv) {
	read(a);
	read(argv...);
}

const int N = 1e5 + 10;
int x[N], p[N], s, n;

LL Calc(int l, int r, int t) {
	if (s < x[l]) return x[r] - s;
	if (s > x[r]) return s - x[l];
	if (p[l] >= p[r]) return p[l] += p[r], Calc(l, r - 1, l) + (t == r ? x[r] - x[l] : 0);
	else return p[r] += p[l], Calc(l + 1, r, r) + (t == l ? x[r] - x[l] : 0);
}

signed main() {
	read(n, s);
	for (int i = 1; i <= n; ++ i) read(x[i], p[i]);
	std::cout << Calc(1, n, p[n] > p[1] ? 1 : n) << std::endl;
	return 0;
}