#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

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

typedef long double ld;
typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;

#define ff first
#define ss second
#define pb push_back
#define int long long   // Make sure to use ll everywhere while commenting this, to avoid overflow
#define sz(v) (int)v.size()
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define f(i,l,r) for(long long i=l;i<=r;i++)
#define rf(i,r,l) for(long long i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }


const int N = 3e5 + 5, mod = 1e9 + 7, bit = 61;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}

bool fun1(pair<pll, int> &x, pair<pll, int> &y)
{
	if (x.ff.ff == y.ff.ff)
	{
		return x.ff.ss < y.ff.ss;
	}
	return x.ff.ff < y.ff.ff;
}

bool fun2(pair<pll, int> &x, pair<pll, int> &y)
{
	if (x.ff.ss == y.ff.ss)
	{
		return x.ff.ff < y.ff.ff;
	}
	return x.ff.ss < y.ff.ss;
}

signed main()
{
	fast;

	int t = 1;
// 	cin >> t;
	f(tc, 1, t)
	{
		int n;
		cin >> n;
		pair<pll, int> a[n + 1];
		f(i, 1, n)
		{
			cin >> a[i].ff.ff >> a[i].ff.ss;
			a[i].ss = i;
		}
		vector<pll> v;
		int tk = min(n, 250LL);
		bool taken[n + 1] = {0};
		sort(a + 1, a + n + 1, fun1);
		f(i, 1, tk)
		{
			if (taken[a[i].ss])
			{
				continue;
			}
			v.pb({a[i].ff.ff, a[i].ff.ss});
			taken[a[i].ss] = 1;
		}
		reverse(a + 1, a + n + 1);
		f(i, 1, tk)
		{
			if (taken[a[i].ss])
			{
				continue;
			}
			v.pb({a[i].ff.ff, a[i].ff.ss});
			taken[a[i].ss] = 1;
		}
		sort(a + 1, a + n + 1, fun2);
		f(i, 1, tk)
		{
			if (taken[a[i].ss])
			{
				continue;
			}
			v.pb({a[i].ff.ff, a[i].ff.ss});
			taken[a[i].ss] = 1;
		}
		reverse(a + 1, a + n + 1);
		f(i, 1, tk)
		{
			if (taken[a[i].ss])
			{
				continue;
			}
			v.pb({a[i].ff.ff, a[i].ff.ss});
			taken[a[i].ss] = 1;
		}
		int mx1 = -inf, mx2 = -inf;
		f(i, 0, sz(v) - 1)
		{
			f(j, i + 1, sz(v) - 1)
			{
				int val = max(abs(v[j].ff - v[i].ff), abs(v[j].ss - v[i].ss));
				if (val > mx1)
				{
					mx2 = mx1;
					mx1 = val;
				}
				else if (val > mx2)
				{
					mx2 = val;
				}
			}
		}
		cout << mx2 << endl;
	}
	return 0;
}
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}
bool c1(pll a, pll b) {
	ll x = 2 * a.fi + a.se;
	ll y = 2 * b.fi + b.se;
	if (x > y) return true;
	else return false;
}
int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n;
	multiset<pair<ll, ll>, std::function<bool(const pair<ll, ll> &, const pair<ll, ll> &)>> s(c1); //c1 is a function
	ll sum = 0;
	rep(i, n) {
		cin >> x >> y;
		sum -= x;
		s.insert({x, y});
	}
	ll cnt = 0;
	// for (auto u : s) {
	// 	cout << u.fi << ' ' << u.se << '\n';
	// }
	while (sum <= 0) {
		auto itr = *s.begin();
		sum += 2 * itr.fi + itr.se;
		s.erase(s.begin());
		cnt++;
	}
	cout << cnt;


	return 0;


}





















