n, m = gets.split.map(&:to_i)

@g = Array.new(n+1){[]}
m.times do
  s, e = gets.split.map(&:to_i)
  @g[s] << e
end

@dp = Array.new(n+1, -1)

def rec(v)
  return @dp[v] if @dp[v] != -1
  res = 0
  @g[v].each do |nv|
    d = rec(nv) + 1
    res = d if d > res
  end
  @dp[v] = res
end

ans = 0
(1..n).each do |v|
  d = rec(v)
  ans = d if d > ans
end
puts ans
