#include <bits/stdc++.h>
#define FIN "spectacole.in"
#define FOUT "spectacole.out"
#include <vector>
#include <algorithm>
typedef struct {
int start,
end;
} Interval;
bool cmp(Interval I1, Interval I2) {
return I2.end > I1.end;
}
int main(int argc, char const *argv[]) {
int n, x, y;
Interval I;
std::vector<Interval> spectacles;
//freopen(FIN, "r", stdin);
//freopen(FOUT, "w", stdout);
std::cin>>n;
for(int i = 0; i < n; ++i) {
std::cin>>x>>y;
I.start = x;
I.end = y;
spectacles.push_back(I);
}
//for(auto x: spectacles) {
//std::cout<<x.start<<" "<<x.end<<std::endl;
//}
//std::cout<<std::endl;
sort(spectacles.begin(), spectacles.end(), cmp);
//for(std::vector<Interval>::iterator it = spectacles.begin(); it!=spectacles.end(); ++it)
//std::cout<< (*it).start<<" "<<(*it).end<<"\n";
int curr = spectacles[0].end;
int i = 1;
int count = 1;
while (i < n){
if(spectacles[i].start >= curr) {
curr = spectacles[i].end;
count++;
}
i++;}
std::cout<<count;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgRklOICJzcGVjdGFjb2xlLmluIgojZGVmaW5lIEZPVVQgInNwZWN0YWNvbGUub3V0IgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdHlwZWRlZiBzdHJ1Y3QgewogICAgaW50IHN0YXJ0LAogICAgICAgIGVuZDsKfSBJbnRlcnZhbDsKCmJvb2wgY21wKEludGVydmFsIEkxLCBJbnRlcnZhbCBJMikgewogICAgIHJldHVybiBJMi5lbmQgPiBJMS5lbmQ7Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyIGNvbnN0ICphcmd2W10pIHsKCiAgICBpbnQgbiwgeCwgeTsKICAgIEludGVydmFsIEk7CiAgICBzdGQ6OnZlY3RvcjxJbnRlcnZhbD4gc3BlY3RhY2xlczsKCiAgICAvL2ZyZW9wZW4oRklOLCAiciIsIHN0ZGluKTsKICAgIC8vZnJlb3BlbihGT1VULCA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