unittest
{
	assert( [ "5 2", "1 4", "2 5" ].solve == 1 );
	assert( [ "9 5", "1 8", "2 7", "3 5", "4 6", "7 9" ].solve == 2 );
	assert( [ "5 10", "1 2", "1 3", "1 4", "1 5", "2 3", "2 4", "2 5", "3 4", "3 5", "4 5" ].solve == 4 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	auto abs = new long[ 2 ][ m ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	abs.sort();
	
	auto ans = 0L;
	auto bm = long.max;
	foreach( ab; abs )
	{
		if( bm <= ab[ 0 ] )
		{
			ans++;
			bm = ab[ 1 ];
		}
		else
		{
			bm = min( bm, ab[ 1 ] );
		}
	}
	ans++;
	return ans;
}
