#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

FILE *input = fopen("room.inp", "r");
FILE *output = fopen("room.out", "w");

struct room
{
	int a;
	int b;
};

bool cmp(room a, room b)
{
	return a.b < b.b;
}

int main()
{
	int n;
	int count = 1;
	fscanf(input, "%d", &n);
	vector <room> a(n);
	for (int i = 0; i < n; ++i)
	{
		fscanf(input, "%d%d", &a[i].a, &a[i].b);
	}
	sort(a.begin(), a.end(), cmp);
	room temp = a[0];
	for (int i = 1; i < n; i++)
	{
		if (a[i].a > temp.b)
		{
			count++;
			temp = a[i];
		}
	}
	fprintf(output, "%d", count);
	fclose(input);
	fclose(output);
	return 0;
}