# -*- coding: utf-8 -*-

"""

Created on Sat Jan 19 16:05:26 2019

DP_G

@author: maezawa

"""

import sys

sys.setrecursionlimit(10**5)



n, m = list(map(int, input().split()))

v = [-1]*(n+1)

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

for _ in range(m):

    i, j = list(map(int, input().split()))

    adj[i].append(j)

    

def dfs(vi):

    if v[vi] != -1:

        return v[vi]

    res = 0

    for nb in adj[vi]:

        res0 = dfs(nb) +1

        if res < res0:

            res = res0

    v[vi] = res

    return res



ans = 0

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

    current = dfs(node)

    if current > ans:

        ans = current

print(ans)
# -*- coding: utf-8 -*-

"""

Created on Sat Jan 19 16:05:26 2019

DP_G

@author: maezawa

"""

import sys

sys.setrecursionlimit(10**6)



n, m = list(map(int, input().split()))

v = [-1]*(n+1)

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

for _ in range(m):

    i, j = list(map(int, input().split()))

    adj[i].append(j)

    

def dfs(vi):

    if v[vi] != -1:

        return v[vi]

    res = 0

    for nb in adj[vi]:

        res0 = dfs(nb) +1

        if res < res0:

            res = res0

    v[vi] = res

    return res



ans = 0

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

    current = dfs(node)

    if current > ans:

        ans = current

print(ans)

    

# -*- coding: utf-8 -*-
"""
Created on Sat Jan 19 16:05:26 2019
DP_G
@author: maezawa
"""
import sys

sys.setrecursionlimit(10**5)
n, m = list(map(int, input().split()))
v = [-1] * (n + 1)
adj = [[] for _ in range(n + 1)]
for _ in range(m):
    i, j = list(map(int, input().split()))
    adj[i].append(j)


def dfs(vi):
    if v[vi] != -1:
        return v[vi]
    res = 0
    for nb in adj[vi]:
        res0 = dfs(nb) + 1
        if res < res0:
            res = res0
    v[vi] = res
    return res


ans = 0
for node in range(1, n + 1):
    current = dfs(node)
    if current > ans:
        ans = current
print(ans)

# -*- coding: utf-8 -*-
"""
Created on Sat Jan 19 16:05:26 2019
DP_G
@author: maezawa
"""
import sys

sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
v = [-1] * (n + 1)
adj = [[] for _ in range(n + 1)]
for _ in range(m):
    i, j = list(map(int, input().split()))
    adj[i].append(j)


def dfs(vi):
    if v[vi] != -1:
        return v[vi]
    res = 0
    for nb in adj[vi]:
        res0 = dfs(nb) + 1
        if res < res0:
            res = res0
    v[vi] = res
    return res


ans = 0
for node in range(1, n + 1):
    current = dfs(node)
    if current > ans:
        ans = current
print(ans)

-sys.setrecursionlimit(10**5) +sys.setrecursionlimit(10**6)