#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct node
{
int head;
int back;
} nodes[N];
bool com(node a, node b)
{
return a.back < b.back;
}
int main()
{
int total;
cin >> total;
for (int i = 0; i < total; i++)
{
cin >> nodes[i].head >> nodes[i].back;
}
int count = 1;
sort(nodes, nodes + total, com);
for (int i = 1; i < total; i++)
{
if (nodes[i - 1].back <= nodes[i].head)
{
count++;
}
}
cout << count << endl;
return 0;
}