#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int s, e;
};
bool cmp( node a, node b){
return a.e < b.e;
}
node p[105];
int main()
{
int n;
int i, j, k, num;
while( scanf("%d", &n) != EOF && n != 0 ){
for( i = 0; i < n; i++ )
scanf("%d %d", &p[i].s, &p[i].e);
sort(p, p+n, cmp);
num = 1;
j = 0;
for( i = 1; i < n; i++ ){
if( p[i].s >= p[j].e ){
j = i;
num++;
}
}
printf("%d\n", num);
}
return 0;
}