#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 62;
const int mods = 998244353;
const int MAXN = 600005;
const int INF = 0x3f3f3f3f;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
long long s[MAXN];
struct anode {
  long long x, y;
} a[MAXN];
int compare(anode x, anode y) { return x.x < y.x; }
int main() {
  int n = read(), S = read();
  for (int i = 1; i <= n; i++) a[i] = (anode){read(), read()};
  sort(a + 1, a + n + 1, compare);
  int l = 1, r = n, flag = -1;
  while (a[l].x < S && a[r].x > S) {
    if (a[l].y > a[r].y)
      a[l].y += a[r].y, s[l] += s[r] + ((flag != 1) ? (a[r].x - a[l].x) : 0),
          flag = 1, r--;
    else
      a[r].y += a[l].y, s[r] += s[l] + ((flag != 0) ? (a[r].x - a[l].x) : 0),
          flag = 0, l++;
  }
  printf("%lld\n", (a[l].x > S) ? s[r] + a[r].x - S : s[l] + S - a[l].x);
  return 0;
}
