# 要提出！
# 例外捕捉（適当にputs ** exit）を２分探索で特定！
# エラーの原因はスタックオーバーフロー？？
# 2 1
# 1 2

# 4 5
# 1 2
# 1 3
# 3 2
# 2 4
# 3 4
#=> 3

# 6 3
# 2 3
# 4 5
# 5 6
#=> 2

# 5 8
# 5 3
# 2 3
# 2 4
# 5 2
# 5 1
# 1 4
# 4 3
# 1 3
#=> 3

# require 'pry'
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
  test 8 / 0
  @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

ans = 0
N.times do |i|
  if !@check2[i]
    ans = dfs(i) if ans < dfs(i)
  end
end
# puts @dp.max
puts ans
rescue
  puts 2525
  exit
end
