#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,a,b,i;
    cin>>n;
    vector<pair<pair<int,int>,int>> pts;
    for (i=0;i<n;i++)
    {
        cin>>a>>b;
        pts.pb(mp(mp(a,b),0));
    }
    for (i=0;i<n;i++)
    {
        cin>>a>>b;
        pts.pb(mp(mp(a,b),1));
    }
    sort(pts.begin(),pts.end());
    set<pair<int,int>> s;
    int ans=0,mark[2*n]={0};
    for (i=0;i<2*n;i++)
    {
        if (pts[i].ss==0)
            s.insert(mp(pts[i].ff.ss,i));
        else
        {
            int choose=-1;
            for (auto e: s)
            {
                if (e.ff<pts[i].ff.ss && mark[e.ss]==0)
                    choose=e.ss;
            }
            if (choose!=-1)
            {
                ans++;
                mark[i]=1;
                mark[choose]=1;
            }
        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int m;
    cin >> m;
    vector<P> v(m);
    for (P &p:v)cin >> p.first >> p.second;

    ll n = 0, s = 0;
    for (P p : v) n += p.second;
    for (P p : v) s += (p.first * p.second);


    ll start = 9 * n + s;
    ll fin = s % 9;
    if (fin == 0) fin += 9;

    ll ans = (start - fin) / 9 - 1;
    cout << ans << endl;

}
