Problems
Longest Path
Longest Path
There is a directed graph $G$ with $n$ vertices and $m$ edges. The vertices are numbered $1, 2, ..., n$, and for each $i\:(1 \le i \le m)$, the $i$-th directed edge goes from vertex $x_i$ to vertex $y_i$.
$G\:$ does not contain directed cycles.
Find the length of the longest directed path in $G$. Here, the length of a directed path is the number of edges in it.
\InputFile
The first line contains two integers: number of vertices $n\:(2 \le n \le 10^5)$ and number of edges $m\:(1 \le m \le 10^5)$. Each of the next $m$ lines contains two integer $x_i, y_i\:(1 \le x_i, y_i \le n)$ that describe the edge of the graph.
\OutputFile
Print the length of the longest directed path in $G$.
\includegraphics{https://static.eolymp.com/content/lr/lrppgvrc194v5amr0dfe6kjaio.gif}
Input example #1
4 5 1 2 1 3 3 2 2 4 3 4
Output example #1
3
Input example #2
6 3 2 3 4 5 5 6
Output example #2
2
Input example #3
5 8 5 3 2 3 2 4 5 2 5 1 1 4 4 3 1 3
Output example #3
3