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

alias Point = Tuple!(int, "x", int, "lr", int, "idx");

void main() {
    int n, m;
    scan(n, m);

    bool[] ok = new bool[](m + 1);
    Point[] a;

    foreach (i ; 0 .. m) {
        int ai, bi;
        scan(ai, bi);
        a ~= Point(ai, 1, i);
        a ~= Point(bi, 0, i);
    }

    a.sort();

    debug {
        writeln(a);
    }

    int[] f;
    int ans;

    foreach (i ; 0 .. 2*m) {
        debug {
            writeln(f);
        }
        if (a[i].lr == 1) {
            f ~= a[i].idx;
        }
        else {
            if (!ok[a[i].idx]) {
                ans++;

                foreach (fi ; f) {
                    ok[fi] = true;
                }

                f = null;
            }
            
        }
    }

    writeln(ans);
}









































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
