https://www.acmicpc.net/problem/1931
// 회의실배정
int solution(vector<vector<int>> a){
int answer =1;
sort(a.begin(), a.end(), cmp);
int end = a[0][1];
for(int i=1;i<a.size();i++){
if(a[i][0] >= end){
answer++;
end = a[i][1];
}else{
if(a[i][1]< end){
end = a[i][1];
}
}
}
return answer;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N; cin >> N;
pair<int, int> schedule[100000];
for (int i = 0; i < N; ++i) {
cin >> schedule[i].second >> schedule[i].first;
}
sort(schedule, schedule + N);
int cnt = 0;
int t = 0;
for (int i = 0; i < N; ++i) {
if (t > schedule[i].second) continue;
cnt++;
t = schedule[i].first;
}
cout << cnt;
return 0;
}