#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


vector< pll > v;
ll n;
ll h[5005], p[5005];
ll dp[5005][5005];
const ll inf = 1e16;
int main()
{
        cin >> n;
        v.pb(make_pair(-2LL , -2LL));
        for(ll i=1;i<=n;i++) {
                cin >> h[i] >> p[i];
                v.pb(make_pair(h[i]+p[i], i));
        }
        sort(v.begin(), v.end());
        for(ll i=1;i<=n;i++) dp[0][i] = inf;
        dp[0][0] = 0;
        for(ll i=1;i<=n;i++) {
                ll id = v[i].second;
                for(ll j = 0; j <= n; j++) {
                        dp[i][j] = dp[i-1][j];
                        if(j && dp[i-1][j-1] <= h[id]) dp[i][j] = min(dp[i][j], p[id] + dp[i-1][j-1]);
                }
        }
        for(ll i=n;i>=0;i--){
                if(dp[n][i] != inf) {
                        cout << i << endl; return 0;
                }
        }
        return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool compareg(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first > b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};



int main() {
    ll N;
    cin>>N;
    vector<Pi>ab(N);
    vector<Pi>cd(N);
    rep(i,N){
        ll a,b;
        cin>>a>>b;
        ab[i] = mp(a,b);
    }

    rep(i,N){
        ll a,b;
        cin>>a>>b;
        cd[i] = mp(a,b);
    }

    sort(all(ab),compareg);
    sort(all(cd),compare);

    ll ans = 0;
    rep(i,N){
        rep(j,N){
            if(ab[i].first < cd[j].first && ab[i].second <cd[j].second){
                ab[i].first = INF;
                cd[j].first = -INF;
                //cout<<i<<" "<<j<<endl;
                ans++;
                break;
            }
        }
    }

    cout << ans<<endl;
    return 0;
    

}
