import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;

void main()
{
    auto nm = readln.chomp.split.to!(long[]);
    long N = nm[0];
    long M = nm[1];

    long[] A = new long[](M);
    long[] B = new long[](M);

    foreach (i; 0 .. M)
    {
        auto ab = readln.chomp.split.to!(long[]);
        A[i] = ab[0];
        B[i] = ab[1];
    }

    zip(A, B).sort!((a, b) => a[1] < b[1]);
    long cnt;
    long x = long.min;
    foreach (i; 0 .. M)
    {
        // writeln(A[i], ", ", B[i]);
        if (x < A[i])
        {
            x = B[i] - 1;
            cnt++;
        }
    }
    cnt.writeln;
}
