#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
struct Recta {
int width;
int height;
Recta(int _w = 0, int _h = 0) :width(_w), height(_h) {};
};
bool m_comp(const Recta& a, const Recta& b) {
if (a.width == b.width) {
return a.height < b.height;
}
else {
return a.width < b.width;
}
}
int maxCount(int number, vector<Recta> datas) {
int res = 1;
int outW, outH;
sort(datas.begin(), datas.end(), m_comp); //按照width升序排序
outW = datas[0].width;
outH = datas[0].height;
for (int i = 1; i < number; i++) {
if (datas[i].width > outW && datas[i].height > outH) {
res++;
outW = datas[i].width;
outH = datas[i].height;
}
}
return res;
}
int main() {
int number;
Recta temp;
while (cin>>number) {
vector<Recta> datas(number);
for (int i = 0; i < number; i++) {
cin >> temp.width >> temp.height;
datas[i] = temp;
}
cout << maxCount(number,datas) << endl;
}
//system("pause");
return 0;
}