#include<bits/stdc++.h>usingnamespacestd;
structTime {int begin;
int end;
};
int ans = 0;
Time times[101];
boolcmp(Time a,Time b){
return a.end < b.end; // 越早结束越好
}
intmain(){
int n;
while (cin >> n && n != 0)
{
for(int i = 0; i < n; i++) {
cin >> times[i].begin >> times[i].end;
}
sort(times, times + n, [&](Time a, Time b) {
return a.end < b.end;
});
int lastProgram_end = times[0].end;
ans = 1; // 第一个节目必须加上for(int i = 1; i < n; i++) {
if (lastProgram_end <= times[i].begin) { // 上一个节目结束了 才可以开始下一个节目
ans++;
lastProgram_end = times[i].end;
}
}
cout << ans << endl;
}
return0;
}