import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto M = RD!long;

	long[] a, b;
	foreach (i; 0..M)
	{
		a ~= RD!long;
		b ~= RD!long;
	}

	auto index = new size_t[](M);
	makeIndex(a, index);

	auto dp = new long[](N+1);
	fill(dp, long.max);
	long pos;
	foreach (i; 0..N)
	{
		if (dp[i] >= i + 1)
			dp[i+1] = dp[i];

		auto j = index[pos];
		if (a[j] <= i + 1)
		{
			dp[i+1] = min(dp[i+1], b[j] - 1);
			++pos;
			if (pos >= M) break;
		}
	}

	long ans;
	long last;
	foreach (e; dp)
	{
		if (e == long.max)
		{
			last = 0;
			continue;
		}
		else if (e > last) ++ans;

		last = e;
	}

	//stderr.writeln(dp);
	writeln(ans);
	stdout.flush();
}