Problem:
Score : 100 points

Problem Statement

There is a directed graph G with N vertices and M edges.
The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to 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.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq x_i, y_i \leq N

All pairs (x_i, y_i) are distinct.

G does not contain directed cycles.

Input

Input is given from Standard Input in the following format:

N M
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print the length of the longest directed path in G.

Sample Input 1

4 5
1 2
1 3
3 2
2 4
3 4

Sample Output 1

3

The red directed path in the following figure is the longest:

Sample Input 2

6 3
2 3
4 5
5 6

Sample Output 2

2

The red directed path in the following figure is the longest:

Sample Input 3

5 8
5 3
2 3
2 4
5 2
5 1
1 4
4 3
1 3

Sample Output 3

3

The red directed path in the following figure is one of the longest:

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

//close stdin
//https://codeforces.com/problemset?order=BY_RATING_ASC&tags=binary+search%2C1300-
#include <bits/stdc++.h>
using namespace std;
long long  gcd(long long  a, long long b){ 
	if (a == 0) 
		return b;  
	return gcd(b % a, a);  
	} 
long long lcmm(long long a,long long b){
	
return (a*b)/gcd(a, b);
}
	
int mod=998244353;
long long summ(long long x){
	long long ans=0;
	while(x!=0){
		ans+=(x%10);
		x=x/10;
	}
	return ans;
	
}
bool prime[1000003]; 
void SieveOfEratosthenes() 
{ 
	int n=1000002;
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 

} 



long long INF=1000000000000;
//long long INF=1000;


void dfs(vector<vector<int>> arr,vector<int> &visited,vector<int> &count,int node){

	//visited[node]++;

	for(int i=0;i<arr[node].size();i++){
		int x=arr[node][i];

			dfs(arr,visited,count,x);
			if(count[node]<=count[x]){
				count[node]=count[x]+1;
				visited[node]=x;
			}

	}
	

}
int main(){
	//freopen ("t.txt","r",stdin);
	int n,m;
	scanf("%d %d",&n,&m);

	vector<vector<int>> arr(n+1);
	vector<int> visited(n+1,-1),count(n+1,0);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		arr[a].push_back(b);
	}
	int maxx=0,tem=0;
	for(int i=1;i<=n;i++){
		if(visited[i]==-1){
			dfs(arr,visited,count,i);
			if(maxx<count[i]){
				tem=i;
				maxx=count[i];
			}
		}
	}
	vector<char> ans;
	cout<<maxx;
	// while(visited[tem]!=-1){
	// 	cout<<visited[tem];
	// 	tem=visited[tem];

	// }

			

	


	

	



return 0;
}