#include <bits/stdc++.h>
struct node {
int x;
int y;
};
bool cmp(node x1, node x2) {
return x1.y < x2.y;
}
using namespace std;
int main() {
node a[1000005];
int n, st;
int ans = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y;
}
sort(a , a + n , cmp);
st = a[1].y;
int i = 1;
while (i <= n) {
i++;
if (a[i].x >= st) {
ans++;
st = a[i].y;
}
}
cout << ans;
return 0;
}