/*
http://codeup.cn/problem.php?cid=100000584&pid=0
*/
#include <iostream>
using namespace std;
#include <algorithm>
struct Televison
{
int si,ei;
};
bool com(Televison t1,Televison t2)
{
if(t1.si!=t2.si)
{
return t1.si>t2.si;按左端点从大到小排序,如果左端点相同,则按照右端点从小到大排序
}
return t1.ei<t2.ei;
}
int main()
{
int n;
while(cin>>n&&n)
{
Televison t[150];
for(int i=0;i<n;i++)
{
cin>>t[i].si>>t[i].ei;
}
sort(t,t+n,com);
int last=t[0].si,count=1;
for(int i=1;i<n;i++)
{
if(last>=t[i].ei)
{
count++;
last=t[i].si;
}
}
cout<<count<<endl;
}
return 0;
}