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

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new int[][](N);
    auto D = new int[](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        D[s[1]-1] += 1;
    }

    DList!int q;
    foreach (i; 0..N) if (D[i] == 0) q.insertBack(i);

    auto dp = new long[](N+1);

    while (!q.empty) {
        auto n = q.front;
        q.removeFront;
        foreach (m; G[n]) {
            dp[m] = max(dp[m], dp[n] + 1);
            D[m] -= 1;
            if (D[m] == 0) q.insertBack(m);
        }
    }

    dp.reduce!max.writeln;
}
