#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define int long long
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 998244353;
//__________THE GAME IS ON__________/
void solve()
{
      int n;
      cin >> n;
      vector<pair<int,int>>v(n),res(n);
      for(int i=0;i<n;i++)
      {
             cin >> v[i].ff >> v[i].ss;
             res[i].ff = (2*v[i].ff)+v[i].ss;
             res[i].ss = v[i].ff;
      }
      sort(all(res));
      reverse(all(res));
      int pre[n+2],suf[n+2];
      pre[0] = 0; pre[n+1]=0;suf[0]=0;suf[n+1]=0;
      for(int i=0;i<n;i++) pre[i+1] = pre[i] + (res[i].ff-res[i].ss);
      for(int i=n;i>0;i--) suf[i]=suf[i+1] + res[i-1].ss;
      // for(int i=0;i<=n+1;i++)cout << pre[i] << " ";
      // cout << endl;
      // for(int i=0;i<=n+1;i++)cout << suf[i] << " ";
      // cout << endl;
      int lo = 0 ,hi = n-1,mid,ans;
      while(lo<=hi)
      {
             mid = (lo+hi)/2;
             int res = pre[mid+1]- suf[mid+2];
             // cout<<pre[mid]<<" "<<suf[mid+1]<<endl;
             if(res>0)
             {
                    ans = mid+1;
                    hi  = mid-1;
             }
             else
             {
                    lo = mid+1;
             }
      }
      cout << ans << endl;
      
}
int32_t main()
{
   high_functioning_sociopath
   //pre();
   ll t=1;
  // cin>>t;
   while(t--)
   {
      solve();
   }
}
#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
using ll = long long;
using P = pair<ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cout << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    I(ll, N);
    ll cnt = 0;
    umap<ll, bool> mp;
    FOR(i, sqrt(N)+1, 2){
        ll cnt = 0;
        for(ll j=(ll)i*i; j<=N;){
            mp[j] = true;
            if(j < 0){
                O(i, j, cnt);
            }
            if(j>N/i){
                break;
            }
            j*=i;cnt++;
        }
    }
    cout << N-mp.size() << el;
}
