require 'set'

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

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

MEMO = Array.new(N + 1, nil)

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

  edges[x] << y
end

def calc(edges, i)
  return MEMO[i] if MEMO[i]

  return 0 if edges[i].empty?

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

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