#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <algorithm>
using namespace std;
struct TVprogram {
int start;
int end;
bool operator <(TVprogram b) const {
return end < b.end; //结束越早越靠前
}
};
TVprogram buff[100];
int main() {
int n, i,count = 1;
TVprogram lastProgram = buff[0];
while ((scanf("%d",&n) != EOF))
{
if (n == 0) break;
for (i = 0; i < n; i++)
scanf("%d%d", &buff[i].start, &buff[i].end);
//每次选择结束时间最早的
sort(buff, buff + n);
for (i = 1; i < n;i++) {
if (buff[i].start >= lastProgram.end) {
count++;
lastProgram = buff[i];
}
}
printf("%d\n", count);
}
return 0;
}