#include <iostream>
#include <algorithm>
struct ss{
int a;
int b;
}q[1000];
int ww (ss x, ss y){
if(x.b < y.b)
return 1;
else
if(x.b == y.b)
if(x.a < y.a)
return 1;
else
return 0;
else
return 0;
}
using namespace std;
int main(){
int n, i, k, t;
while(scanf("%d", &n) && (n != 0)){
for(i = 0; i < n; i++){
scanf("%d%d", &q[i].a, &q[i].b);
}
sort(q, q + n, ww);
t = q[0].b;
for(i = 1, k = 1; i < n; i++){
if(t <= q[i].a){
t = q[i].b;
k++;}
}
printf("%d\n", k);
}
return 0;
}