#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;
const int INF=100005;
const int MAX=505;

int yM[MAX];
char g[MAX][MAX],chk[MAX];
int t;
int SearchPath(int u)
{
    int v;
    for(v=1;v<=t;v++)
    {
        if(g[u][v]&&!chk[v])
        {
            chk[v]=1;
            if(yM[v]==-1||SearchPath(yM[v]))
            {
                yM[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
int MaxMatch()
{
    int u,ret=0;
    memset(yM,-1,sizeof(yM));

    for(u=1;u<=t;u++)
    {
            memset(chk,false,sizeof(chk));
            if(SearchPath(u))
                ret++;

    }
    return ret;
}
int main()
{
    freopen("in.txt","r",stdin);
    int a,b,ans,mark[65];

    while(scanf("%d",&t)!=EOF)
    {
        memset(g,0,sizeof(g));
        for(int i=1;i<=t;i++)
        {
            scanf("%d%d",&a,&b);
            a=a+1;
            b=t-b;
            for(int j=a;j<=b;j++)
                g[i][j]=1;
        }
        ans=MaxMatch();
        printf("%d\n",ans);
    }
    return 0;
}