n, m = gets.split.map(&:to_i)
edges = Array.new(m){gets.split.map(&:to_i)}

moves = Hash.new([])
edges.each{|e| moves[e.first] += [e.last]}

ans = 0
starts = (1..n).to_a - edges.map(&:last)
starts.each do |s|
  d = Hash.new(0)
  queue = []
  queue.push(s)
  until queue.empty?
    u = queue.pop
    moves[u].each do |v|
      d[v] = d[u] + 1
      queue.push(v)
    end
  end
  d_max = d.values.max
  ans = d_max if d_max > ans
end
puts ans
