//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 100111;
int n;
ll X[maxn], P[maxn], S;
struct movement
{
	ll pos, ans;
	movement move(ll x)
	{
		movement ret;
		ret.ans = ans+abs(x-pos);
		ret.pos = x;
		return ret;
	}
};
movement solve(int l, int r, ll dl, ll dr)
{
	if (S<=X[l]) return movement({X[r], X[r]-S});
	if (X[r]<=S) return movement({X[l], S-X[l]});
	if (P[l]+dl<P[r]+dr)
	{
		return solve(l+1, r, 0, dl+dr+P[l]).move(X[l]);
	}
	else
	{
		return solve(l, r-1, dl+dr+P[r], 0).move(X[r]);
	}
}
int main()
{
	getii(n, S);
	for (int i=1; i<=n; i++) getii(X[i], P[i]);
	cout<<solve(1, n, 0, 0).ans<<endl;
	return 0;
}

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

int main() {
  int N, M;
  cin >> N;
  vector<string>s(N);
  for(int i=0; i<N; i++)cin >> s.at(i);
  cin >> M;
  vector<string>t(M);
  for(int i=0; i<M; i++)cin >> t.at(i);
  
  int red =0;
  int blue=0;
  int money = 0;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(s.at(i)==s.at(j))blue++;
    }
    for(int j=0; j<M; j++){
      if(s.at(i)==t.at(j))red++;
    }
    money = max(money, blue-red);
    red=0; blue=0;
  }
  
  cout << money << endl;
}