#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b) {
if (a.second == b.second)
return a.first < b.first;
return a.second < b.second;
}
vector<pair<int, int>> meeting;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n;
cin >> n;
int a, b;
for (int i = 0; i < n; i++)
{
cin >> a >> b;
meeting.push_back({ a,b });
}
sort(meeting.begin(), meeting.end(),compare);
int endtime = meeting[0].second;
int cnt = 1;
for (int i = 1; i < n; i++)
{
if (endtime <= meeting[i].first) {
cnt++;
endtime = meeting[i].second;
}
}
cout << cnt;
}