#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 110;
const int inf=0x3f3f3f3f;
typedef long long ll;
int n,m,k,t;
int x,y,z;
struct node
{
int a,b;
}p[maxn];
bool cmp(struct node a,struct node b)
{
return a.b<b.b;
}
int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
int num=0;
for(int i=1;i<=n;++i){
scanf("%d %d",&p[i].a,&p[i].b);
}
int ans=0;
sort(p+1,p+1+n,cmp);
int t=0;
for(int i=1;i<=n;++i)
{
if(p[i].a>=t)
{
++ans;
t=p[i].b;
}
}
printf("%d\n",ans);
}
}