begin
N, M = gets.split.map(&:to_i)
@lines = {}
M.times do
  s, t = gets.split.map(&:to_i)
  (@lines[s-1] ||= []) << t-1
end
# p lines
@dp = Array.new(N, 0)
# binding.pry
@check2 = Array.new(N, false)
def dfs(i)
  if @check2[i]
    return @dp[i]
  end
  @check2[i] = true
  res = 0
  if @lines[i]
    @lines[i].each do |to|
      pre = dfs(to) + 1
      res = pre if res < pre
    end
  end
  return @dp[i] = res
end
rescue
  puts 2525
  exit
end
ans = 0
N.times do |i|
  if !@check2[i]
    ans = dfs(i) if ans < dfs(i)
  end
end
# puts @dp.max
puts ans