#include<bits/stdc++.h>
using namespace std;
struct TV {
int st;
int en;
}tv[105];
bool cmp(const TV& a, const TV& b)
{
if (a.en < b.en) return true;
else return false;
}
int main()
{
int n, sum = 0, fen = 0;
cin >> n;
while (n != 0)
{
for (int i = 1; i <= n; i++)
{
cin >> tv[i].st >> tv[i].en;
}
sort(tv + 1, tv + n + 1, cmp);
sum++;
fen = tv[1].en;
for (int i = 2; i <= n; i++)
{
if (tv[i].st >= fen)
{
sum++;
fen = tv[i].en;
}
}
cout << sum << endl;
scanf("%d", &n);
sum = 0;
}
return 0;
}