#include<iostream>
#include<algorithm>
#include<cstdio>
#define maxn 100005
using namespace std;

int n, m;
int a1,a2;
int map[maxn];
int main()
{
	int t, tm;
	int sum = 0;
	cin >> m>> n;
	for (int i = 0;i < n;i++)
	{
		scanf("%d%d", &a1, &a2);
		if((map[a1]!=0&&a2<map[a1])||map[a1]==0)
			map[a1] = a2;
		//cout << map[a1] << endl;;
	}
	for (int i = 0;i < n;i++)
	{
		int j;
		if (map[i] != 0)
		{
			//printf("i=%d\n",map[i]);
			for (j = i + 1;j < map[i];j++)
			{
				//printf("j=%d\n", j);
				if (map[j] <= map[i])
				{
					sum++;
					i = map[i] - 1;
					break;
				}
				i = j - 1;
				break;

			}
			if (j == map[i])
			{
				sum++;
				i = j-1;
			}
		}
	}
	
	printf("%d\n",sum+1);
	//getchar();
	//getchar();
	return 0;
}