#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
struct nod{
int x;
int y;
};
bool cmp(nod a, nod b)
{
if(a.x!=b.x)
{
return a.x>b.x;
}else
{
return a.y>b.y;
}
}
int main()
{
while(1)
{
int n;
scanf("%d",&n);
//cin>>n;
if(n==0)
{
break;
}
vector<nod> ve;
for(int i=0;i<n;i++)
{
nod t;
scanf("%d%d",&t.x,&t.y);
//cin>>t.x>>t.y;
ve.push_back(t);
}
sort(ve.begin(),ve.end(),cmp);
int jg=1;//第一个肯定是猴王
int zd=ve[0].y;
for(int i=1;i<ve.size();i++)
{
if(ve[i].y>zd)
{
jg++;
zd=ve[i].y;
}
}
printf("%d\n",jg);
//cout<<jg<<endl;
}
return 0;
}