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

#define Re return
#define In inline
#define Rg
#define Op operator
#define St static
#define inc(l, i, r) for(Rg int i=l; i<r; ++i)
#define dec(l, i, r) for(Rg int i=r; i>l; --i)
#define fst first
#define snd second

typedef long long ll;

int main()
{
    St int n, s;
    St pair<int, ll> a[1<<17];
    scanf("%d%d", &n, &s);
    inc(0, i, n)
        scanf("%d%lld", &a[i].fst, &a[i].snd);
    sort(a, a+n);
    Rg int m=lower_bound(a, a+n, make_pair(s, 0ll))-a;
    Rg int l=0, r=n-1;
    St ll f[1<<17];
    for(;l<m && m<=r;)
    {
        if(a[l].snd<a[r].snd)
            f[r]=max(f[r], f[l]+a[r].fst-a[l].fst), a[r].snd+=a[l++].snd;
        else
            f[l]=max(f[l], f[r]+a[r].fst-a[l].fst), a[l].snd+=a[r--].snd;
    }
    printf("%lld\n", l<m? f[l]+s-a[l].fst: f[r]+a[r].fst-s);
    Re 0;
}
