#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector<int> l(n * 2);
  rep(i, 0, n * 2) cin >> l[i];
  sort(l.begin(), l.end());

  int ans = 0;
  rep(i, 1, n * 2) {
    ans += min(l[i], l[i - 1]);
    i++;
  }

  cout << ans << endl;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int n,s,x[N];
ll t[N],p[N];

void solve(int l,int r) {
	if (x[r]<s) {
		fo(i,l,r) t[i]=s-x[i];
		return;
	}
	if (x[l]>s) {
		fo(i,l,r) t[i]=x[i]-s;
		return;
	}
	if (p[l]>=p[r]) {
		p[l]+=p[r];
		solve(l,r-1);
		t[r]=t[l]+x[r]-x[l];
	} else {
		p[r]+=p[l];
		solve(l+1,r);
		t[l]=t[r]+x[r]-x[l];
	}
}

int main() {
	n=read();s=read();
	fo(i,1,n) x[i]=read(),p[i]=read();
	solve(1,n);
	printf("%lld\n",max(t[1],t[n]));
	return 0;
}