import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

struct Pair {
    int left;
    int right;
}

void main() {
    int n, m; readf("%d %d\n", &n, &m);
    auto pairs = new Pair[m];
    foreach (ref p ; pairs)
        readf("%d %d\n", &p.left, &p.right);
    pairs.sort!("a.right < b.right");

    int r, ans;
    foreach (p ; pairs) {
        with (p) {
            if (left < r) continue;
            r = right;
            ans++;
        }
    }
    writeln(ans);
}