from sys import stdin, setrecursionlimit

# input = stdin.readline

setrecursionlimit(200000)

N, M = list(map(int, input().split()))

# d = [0] * (N + 1)

adj = [[] for _ in range(N + 1)]

for _ in range(M):

    x, y = list(map(int, input().split()))

    adj[x].append(y)

    # d[y] += 1



dp = [-1] * (N + 1)





def lp(x: 'int') -> 'int':

    if dp[x] >= 0:

        return dp[x]

    else:

        dp[x] = 0

        for y in adj[x]:

            dp[x] = max(dp[x], lp(y) + 1)

        return dp[x]





print((max(lp(i) for i in range(1, N + 1))))

from sys import stdin, setrecursionlimit

input = stdin.readline

setrecursionlimit(200000)

N, M = list(map(int, input().split()))

# d = [0] * (N + 1)

adj = [[] for _ in range(N + 1)]

for _ in range(M):

    x, y = list(map(int, input().split()))

    adj[x].append(y)

    # d[y] += 1



dp = [-1] * (N + 1)





def lp(x: 'int') -> 'int':

    if dp[x] >= 0:

        return dp[x]

    else:

        dp[x] = 0

        for y in adj[x]:

            dp[x] = max(dp[x], lp(y) + 1)

        return dp[x]





print((max(lp(i) for i in range(1, N + 1))))

from sys import stdin, setrecursionlimit

# input = stdin.readline
setrecursionlimit(200000)
N, M = list(map(int, input().split()))
# d = [0] * (N + 1)
adj = [[] for _ in range(N + 1)]
for _ in range(M):
    x, y = list(map(int, input().split()))
    adj[x].append(y)
    # d[y] += 1
dp = [-1] * (N + 1)


def lp(x: "int") -> "int":
    if dp[x] >= 0:
        return dp[x]
    else:
        dp[x] = 0
        for y in adj[x]:
            dp[x] = max(dp[x], lp(y) + 1)
        return dp[x]


print((max(lp(i) for i in range(1, N + 1))))

from sys import stdin, setrecursionlimit

input = stdin.readline
setrecursionlimit(200000)
N, M = list(map(int, input().split()))
# d = [0] * (N + 1)
adj = [[] for _ in range(N + 1)]
for _ in range(M):
    x, y = list(map(int, input().split()))
    adj[x].append(y)
    # d[y] += 1
dp = [-1] * (N + 1)


def lp(x: "int") -> "int":
    if dp[x] >= 0:
        return dp[x]
    else:
        dp[x] = 0
        for y in adj[x]:
            dp[x] = max(dp[x], lp(y) + 1)
        return dp[x]


print((max(lp(i) for i in range(1, N + 1))))

-# input = stdin.readline +input = stdin.readline