class Graph
  def initialize(n)
    @g = Array.new(n){ [] }
    @dp = Array.new(n, -1)
  end
  def add(a,b)
    @g[a] << b
  end
  def bfs(v)
    return @dp[v] if @dp[v] != -1
    return @dp[v] = 0 if @g[v].empty?
    ans = 0
    @g[v].each do |nv|
      len = bfs(nv)
      ans = len if ans < len
    end
    @dp[v] = ans + 1
  end
end

n,m = gets.split.map(&:to_i)
g = Graph.new(n)
m.times do
  x,y = gets.split.map(&:to_i)
  x -= 1
  y -= 1
  g.add(x,y)
end

ans = 0
n.times do |v|
  len = g.bfs(v)
  ans = len if ans < len
end

puts ans