#dt = {} for i in x: dt[i] = dt.get(i,0)+1

import sys;input = sys.stdin.readline

inp,ip = lambda :int(eval(input())),lambda :[int(w) for w in input().split()]



import sys

sys.setrecursionlimit(10**6)



def dfs(u):

    global grpah,vis,dp

    vis.add(u)

    for i in graph[u]:

        if i not in vis:

            dfs(i)

        dp[u] = max(dp[u],dp[i] + 1)



n,m = ip()

graph = {i:[] for i in range(1,n+1)}

for i in range(m):

    a,b = ip()

    graph[a].append(b)

dp = [0]*(n+1)



vis = set()

for i in range(1,n+1):

    if i not in vis:

        dfs(i)

#print(dp)

print((max(dp)))
#dt = {} for i in x: dt[i] = dt.get(i,0)+1

import sys;input = sys.stdin.readline

inp,ip = lambda :int(eval(input())),lambda :[int(w) for w in input().split()]



import sys

sys.setrecursionlimit(10**6)



def dfs(u):

    global grpah,vis,dp

    vis[u] = 1

    for i in graph[u]:

        if not vis[i]:

            dfs(i)

        dp[u] = max(dp[u],dp[i] + 1)



n,m = ip()

graph = {i:[] for i in range(1,n+1)}

for i in range(m):

    a,b = ip()

    graph[a].append(b)



dp = [0]*(n+1)

vis = [0]*(n+1)

for i in range(1,n+1):

    if not vis[i]:

        dfs(i)

#print(dp)

print((max(dp)))
# dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys

input = sys.stdin.readline
inp, ip = lambda: int(eval(input())), lambda: [int(w) for w in input().split()]
import sys

sys.setrecursionlimit(10**6)


def dfs(u):
    global grpah, vis, dp
    vis.add(u)
    for i in graph[u]:
        if i not in vis:
            dfs(i)
        dp[u] = max(dp[u], dp[i] + 1)


n, m = ip()
graph = {i: [] for i in range(1, n + 1)}
for i in range(m):
    a, b = ip()
    graph[a].append(b)
dp = [0] * (n + 1)
vis = set()
for i in range(1, n + 1):
    if i not in vis:
        dfs(i)
# print(dp)
print((max(dp)))

# dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys

input = sys.stdin.readline
inp, ip = lambda: int(eval(input())), lambda: [int(w) for w in input().split()]
import sys

sys.setrecursionlimit(10**6)


def dfs(u):
    global grpah, vis, dp
    vis[u] = 1
    for i in graph[u]:
        if not vis[i]:
            dfs(i)
        dp[u] = max(dp[u], dp[i] + 1)


n, m = ip()
graph = {i: [] for i in range(1, n + 1)}
for i in range(m):
    a, b = ip()
    graph[a].append(b)
dp = [0] * (n + 1)
vis = [0] * (n + 1)
for i in range(1, n + 1):
    if not vis[i]:
        dfs(i)
# print(dp)
print((max(dp)))

-    vis.add(u) +    vis[u] = 1 -        if i not in vis: +        if not vis[i]: -vis = set() +vis = [0] * (n + 1) -    if i not in vis: +    if not vis[i]: