require 'set'

N, M = gets.chomp.split.map(&:to_i)

edges = Array.new(N + 1) { [] }
starts = Set.new((1..N).to_a)

M.times do
  x, y = gets.chomp.split.map(&:to_i)

  edges[x] << y

  starts.delete(y)
end

def calc(edges, i)
  return 0 if edges[i].empty?

  edges[i].map {|j| calc(edges, j) }.max + 1
end

print starts.map {|i| calc(edges, i) }.max