Language: C++

/*
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNMMMMMNmmmNNMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNNMMNNNMMMMMMMNNNNNNNNMMMMNmddNNMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmNNNNNNNNNNNNNNNNNNNmmmNNNNNNNNdyhmNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNmmmNmmmmNmmmNmNNmmNNNmmmmmmmmmmmmmmmmddNNNdhmNMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmmmdddmdhddmmmmmmmmmmmmmmdddddddhhhdhhhhddmNmddNMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmmmmmdhhhyhddddhhhhhhyyhyyhhhddddmddhhyyyyhhddmmmhhmMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmmmddddddyyyyhhyyyoysoooooooooooooosssyhdmmddhhhhdddmmmhhmMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMNNNNNmmddddhdhhhyssssoosoos+/+++++++++++++++ooooossssyyhhhhhhhhddyhmMMMMMMMMM
MMMMMMMMMMMMMMMMMMNMMMMNmmmmmddddhhyys+ooo++++oo+///////////////////+++oooooossyysyysyyyddhmNMMMMMMM
MMMMMMMMMMMMMMMMMNNNNNNNdmmddddhhhy+o////////////::///:::--::::::://///++ooosssyyyysssssyyddmNMMMMMM
MMMMMMMMMMMMMMMMMNNNmmmNddddhhhyss+o/::://:::/::::::-------::::::::::///////+++oossoooossyydmmMMMMMM
MMMMMMMMMMMMMMMNNmNmmddmdhhhyssoo++::/://:::::::::-----------------:::::///////++++oooooosyhmmNMMMMM
MMMMMMMMMMMMMMNmNdmdmdhmhhyysooo+/::/:::::::--:----------------------:::::::::////++++++oosyhmmMMMMM
MMMMMMMMMMMMMNNmNmmdddyhhhsooo++:://--::::::-------------....-----------:::::::://////+++ooshmNNMMMM
MMMMMMMMMMMMNNNmNmddhhhhhyo+o++/:/:----::-------:-----.......------------:::::::////////+oosymNNMMMM
MMMMMMMMMMMMNNNmNmddhyyyyys/+++:/:---------:/::---...........-.--....--------:::::::///+++osydNNMMMM
MMMMMMMMMMMMNNNNNmdddysh+ys//+/:/--------://:--....--...`..--------------------::::::/++++syhhmNMMMM
MMMMMMMMMMMNNNNmmmddhhoo++s///:/:-----:::/:--...-::---::://++///:--:::-----------:::/++ooyyhhdmNNMMM
MMMMMMMMMMMNNNNmmmmdhho+s:s+/::/------:::---...-::/+++/:////::-::---:::-:--------:::oosooshdmmNNMMMM
MMMMMMMMMMMNNNNmmNddhys/+++o/:::-----:::--...-:/+++:-...---:---------------------::oss+oosyhdmMNMMMM
MMMMMMMMMMMNNNNmNmddyys//+/+//:-----::------:++/:-....`....---------------------::+yy++++oosshNNMMMM
MMMMMMMMMMMNNNNNmdmdsys+//+///-----::------/+/:-...``......---------........---::/sy+///+++ossmNMMMM
MMMMMMMMMMMNNNNmmdddyy+++//:::---------:--://:...`....-:///++/:-----........---::soo///++ooosymNMMMM
MMMMMMMMMMMNNNNmmdydsy//o:::------------://:-......:/++/+oyhhyo/:---.........--:oos:/ossyyhhhdmNMMMM
MMMMMMMMMMMNNNNNmhyyos///+::-----------::-......-:////+oymNNmhoo+-.--...````..-:sy//ohmNNhdNmmmMMMMM
MMMMMMMMMMMNMNNNmhs+++//:///:---................:::++:.:NMMMMNdos/.--.``````..-+y+:+-mMMMNhmNmNMMMMM
MMMMMMMMMMMMMMNNmy++//+//:/:/---...............-/so:`` .hyNMMMNyoy---``````...-/d/:-`+NMMMNmmNMMMMMM
MMMMMMMMMNmmmmNNmy+//:/+/::::--.......```.....-////://:.:shdddhsoo:--.........--ss--::oyhdmmmNMMMMMM
MMMMMMMMds+///+osoo+/::/+/::---........```....-.......---::::::/::---........-.::yo---:::/+sdmMMMMMM
MMMMMMMh+///:::::--:///:+/:::---....`..`.``.......``````....--:::-----..--....--::ss:--:://oymNMMMMM
MMMMMMd::-/o:--::+/-.-/o/+:-:---.........`.....`````````....----------........----:oy/-:://+ohmNMMMM
MMMMMMh-:.:y-----:os:-.:o//--:--.........``..````...........--------............---:/yo:::++osdmMMMM
MMMMMMN/-:-y:--://-/y+:.:o//-::-............```````........---------.....---......---:oo:::/ooymNMMM
MMMMMMMd-:-s--//:-.:+so:-/+//-/:...........``````````.........-----...------..`....--:/s+:::/++hmMMM
MMMMMMMMd-/o::/-...-:s+::.///+:+--.........````````````.........---...---..--:-----:/+oso::::/+omNMM
MMMMMMMMMm:/s.++:....:s.-+.//+/:/-........````````````````.....-::-...--:/+/:--://++o+oso:::://odNMM
MMMMMMMMMMm-/:`:s+:---/s.:o-//+//:-........````````````````...-/+-.....---..-:::://+ossso/:::/+odNMM
MMMMMMMMMMMm::.`./+:://+/./+-+/+//-..........`````````````..-:o+.``.......---:::::/+oyyss/:://+ymMMM
MMMMMMMMMMMMNo-...::-----.://-o/o/+-...............```````..:o:.````......---:/::://oyysy+://+smNMMM
MMMMMMMMMMMMMMd+-..------../:::y++:/.................````../o.````````....--:////++osyhyho//+smNMMMM
MMMMMMMMMMMMMMMMmo:-----..-oy/:/so:/-.....................:o..```````..-:/+ossoosyyhhdhyo///omNMMMMM
MMMMMMMMMMMMMMMMMMmy/:::+ysoss//+ss:/-...................-o:-----::/+osys/--::-/soosyhs/::/+hNMMMMMM
MMMMMMMMMMMMMMMMMMMMNNmNMMdo++o/+oss::-..................-+/++ossssoooossoosyyhyssssyh/::/+hNMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMNmo////sshs::..................-:/-:/ooyyssssossssyssyyhyyhy::/odNMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMmds/::/shds:/-.................::....--/+osyyyyo+oosyyyyyd+:/smNMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMNhhhs/:::ohmh//:--.............-::..`..```..-/++oossooossy+:/hNMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMNdysooso///+shds+/:----------------.......`...-::/+ooossso/+omNMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMNNmdhysyys+/+oo++++sdds+//:----------................--::://///o+mMMMMMMMMMMMMMM
MMNNNNNNNNNNNNNmddhhyssos++sssyo/::+oo++oydhsoo//::------.....``........---::::://o/yNMMMMMMMMMMMMMM
yyyssyyyyyyyyyyyssoooooooo//sy+oso/:::/+oooyhysso++////:---...............-----:/+++mMMMMMMMMMMMMMMM
oooooossssyyyyssoooooooooos/:sh+/+ooo/::-:/+sssssso+++++oo+:--...............--://+hMMMMMMMMMMMMMMMM
++++++ooossssyssoo+oooooooos/:oh+////++++/////+osyyyssoo++shs/:-...........--://+shNMMMMMMMMMMMMMMMM
/////+++ooooossso+++++++++++o+:/sy+++//://///+++++osssossysssyys+::-------:+oooydNMMMMMMMMMMMMMMMMMM
///////+++ooooooo+++/+++///////::/+oso+++/+///::::::::////+ooydhyhhyssoosyhdddddmNMMMMMMMMMMMMMMMMMM
////////++++ooo+++++////////:::::::::/++o+++++++/////////++oydysyhhhhdddddddddddddmmNmNNMMMMMMMMMMMM
::://///++++++++++++///////:::::::::::::::////////////++oshhyssyyyhhhdddddddddddhhhhhhdddmmNNMMMMMMM
/:::///+//++++++///+///////:::::::::::::::::::::::///++ooooosssssyyhhhhhddhhhhhhhhhhyyyyyyhdddmMMMMM
/::://+o////+++/////////:::/:::::::::::::::::::://////++++oooooossyyyhhhhhhhhhhhhyyyssoooossyhdmNMMM
*/

/// *********** Coded by Olium_MdioxideN ***********

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define elif else if
#define pb push_back
#define mp make_pair
#define nl '\n'
#define forr(i,b,e) for(int i=b;i<=e;i++)
#define forrv(i,b,e) for(int i=b;i>=e;i--)
#define fors(i,x) for(auto i=x.begin(); i!=x.end(); i++)
#define F first
#define S second
#define mset0(x) memset(x, 0, sizeof x);
#define mset1(x) memset(x, -1, sizeof x);
#define all(x) x.begin(),x.end()
#define pqmin(x) priority_queue<x, vector<x>, greater<x> >
#define pqmax(x) priority_queue<x>
#define sortdsc(x) sort(all(x)); reverse(all(x));
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define mpii map<int,int>
#define pi 3.14159265358979323846D
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) (x*(y/__gcd(x,y)))
#define chkbit(x,p) ((x&(1LL<<p))?1:0)
#define setbit(x,p) x|=(1LL<<p)
#define clrbit(x,p) x=x&(~(1LL<<p))
#define revbit(x,p) (chkbit(x,p)?clrbit(x,p):setbit(x,p))
#define runtime() cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }

#ifndef ONLINE_JUDGE
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,
__attribute__((unused))int LINE_NUM){cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << ") ";stringstream ss;ss<<H;
cerr<<args[idx]<<" = "<<ss.str();dbg_out(args,idx+1,LINE_NUM, T...);}
#define debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define in_file freopen("input.c", "r", stdin)
#define out_file freopen("output.c", "w", stdout)
#else
#define debug(...) 0
#define in_file 0
#define out_file 0
#endif

/// * * *    Main Code Starts Now    * * *

#define MOD 10000007
#define MAX 100010
void olium();

int main()
{
    in_file;
    //out_file;
    fast;
    int t = 1;
    //cin >> t;
    forr(i,1,t)
    {
        //cout << "Case " << i << ": ";
        olium();
    }
    return 0;
}

int n,m;
vector<int> adj[100010];

int dp[100010];

int sol(int cnode)
{
	if(dp[cnode] != -1) return dp[cnode];
	if(adj[cnode].size() == 0) return 0;
	int mx = 0;
	for(auto node : adj[cnode])
	{
		mx = max(mx, 1 + sol(node));
	}
	return dp[cnode] = mx;
}

void olium()
{
	mset1(dp);
    cin >> n >> m;
    forr(i,1,n)
    {
    	adj[i].clear();
    }
    forr(i,1,m)
    {
    	int u,v;
    	cin >> u >> v;
    	adj[u].pb(v);
    }
    int ans = 0;
    forr(i,1,n)
    {
    	ans = max(ans, sol(i));
    }
    cout << ans << nl;
}/*
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNMMMMMNmmmNNMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNNMMNNNMMMMMMMNNNNNNNNMMMMNmddNNMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmNNNNNNNNNNNNNNNNNNNmmmNNNNNNNNdyhmNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNmmmNmmmmNmmmNmNNmmNNNmmmmmmmmmmmmmmmmddNNNdhmNMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmmmdddmdhddmmmmmmmmmmmmmmdddddddhhhdhhhhddmNmddNMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmmmmmdhhhyhddddhhhhhhyyhyyhhhddddmddhhyyyyhhddmmmhhmMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMNNNNNNmmmmddddddyyyyhhyyyoysoooooooooooooosssyhdmmddhhhhdddmmmhhmMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMNNNNNmmddddhdhhhyssssoosoos+/+++++++++++++++ooooossssyyhhhhhhhhddyhmMMMMMMMMM
MMMMMMMMMMMMMMMMMMNMMMMNmmmmmddddhhyys+ooo++++oo+///////////////////+++oooooossyysyysyyyddhmNMMMMMMM
MMMMMMMMMMMMMMMMMNNNNNNNdmmddddhhhy+o////////////::///:::--::::::://///++ooosssyyyysssssyyddmNMMMMMM
MMMMMMMMMMMMMMMMMNNNmmmNddddhhhyss+o/::://:::/::::::-------::::::::::///////+++oossoooossyydmmMMMMMM
MMMMMMMMMMMMMMMNNmNmmddmdhhhyssoo++::/://:::::::::-----------------:::::///////++++oooooosyhmmNMMMMM
MMMMMMMMMMMMMMNmNdmdmdhmhhyysooo+/::/:::::::--:----------------------:::::::::////++++++oosyhmmMMMMM
MMMMMMMMMMMMMNNmNmmdddyhhhsooo++:://--::::::-------------....-----------:::::::://////+++ooshmNNMMMM
MMMMMMMMMMMMNNNmNmddhhhhhyo+o++/:/:----::-------:-----.......------------:::::::////////+oosymNNMMMM
MMMMMMMMMMMMNNNmNmddhyyyyys/+++:/:---------:/::---...........-.--....--------:::::::///+++osydNNMMMM
MMMMMMMMMMMMNNNNNmdddysh+ys//+/:/--------://:--....--...`..--------------------::::::/++++syhhmNMMMM
MMMMMMMMMMMNNNNmmmddhhoo++s///:/:-----:::/:--...-::---::://++///:--:::-----------:::/++ooyyhhdmNNMMM
MMMMMMMMMMMNNNNmmmmdhho+s:s+/::/------:::---...-::/+++/:////::-::---:::-:--------:::oosooshdmmNNMMMM
MMMMMMMMMMMNNNNmmNddhys/+++o/:::-----:::--...-:/+++:-...---:---------------------::oss+oosyhdmMNMMMM
MMMMMMMMMMMNNNNmNmddyys//+/+//:-----::------:++/:-....`....---------------------::+yy++++oosshNNMMMM
MMMMMMMMMMMNNNNNmdmdsys+//+///-----::------/+/:-...``......---------........---::/sy+///+++ossmNMMMM
MMMMMMMMMMMNNNNmmdddyy+++//:::---------:--://:...`....-:///++/:-----........---::soo///++ooosymNMMMM
MMMMMMMMMMMNNNNmmdydsy//o:::------------://:-......:/++/+oyhhyo/:---.........--:oos:/ossyyhhhdmNMMMM
MMMMMMMMMMMNNNNNmhyyos///+::-----------::-......-:////+oymNNmhoo+-.--...````..-:sy//ohmNNhdNmmmMMMMM
MMMMMMMMMMMNMNNNmhs+++//:///:---................:::++:.:NMMMMNdos/.--.``````..-+y+:+-mMMMNhmNmNMMMMM
MMMMMMMMMMMMMMNNmy++//+//:/:/---...............-/so:`` .hyNMMMNyoy---``````...-/d/:-`+NMMMNmmNMMMMMM
MMMMMMMMMNmmmmNNmy+//:/+/::::--.......```.....-////://:.:shdddhsoo:--.........--ss--::oyhdmmmNMMMMMM
MMMMMMMMds+///+osoo+/::/+/::---........```....-.......---::::::/::---........-.::yo---:::/+sdmMMMMMM
MMMMMMMh+///:::::--:///:+/:::---....`..`.``.......``````....--:::-----..--....--::ss:--:://oymNMMMMM
MMMMMMd::-/o:--::+/-.-/o/+:-:---.........`.....`````````....----------........----:oy/-:://+ohmNMMMM
MMMMMMh-:.:y-----:os:-.:o//--:--.........``..````...........--------............---:/yo:::++osdmMMMM
MMMMMMN/-:-y:--://-/y+:.:o//-::-............```````........---------.....---......---:oo:::/ooymNMMM
MMMMMMMd-:-s--//:-.:+so:-/+//-/:...........``````````.........-----...------..`....--:/s+:::/++hmMMM
MMMMMMMMd-/o::/-...-:s+::.///+:+--.........````````````.........---...---..--:-----:/+oso::::/+omNMM
MMMMMMMMMm:/s.++:....:s.-+.//+/:/-........````````````````.....-::-...--:/+/:--://++o+oso:::://odNMM
MMMMMMMMMMm-/:`:s+:---/s.:o-//+//:-........````````````````...-/+-.....---..-:::://+ossso/:::/+odNMM
MMMMMMMMMMMm::.`./+:://+/./+-+/+//-..........`````````````..-:o+.``.......---:::::/+oyyss/:://+ymMMM
MMMMMMMMMMMMNo-...::-----.://-o/o/+-...............```````..:o:.````......---:/::://oyysy+://+smNMMM
MMMMMMMMMMMMMMd+-..------../:::y++:/.................````../o.````````....--:////++osyhyho//+smNMMMM
MMMMMMMMMMMMMMMMmo:-----..-oy/:/so:/-.....................:o..```````..-:/+ossoosyyhhdhyo///omNMMMMM
MMMMMMMMMMMMMMMMMMmy/:::+ysoss//+ss:/-...................-o:-----::/+osys/--::-/soosyhs/::/+hNMMMMMM
MMMMMMMMMMMMMMMMMMMMNNmNMMdo++o/+oss::-..................-+/++ossssoooossoosyyhyssssyh/::/+hNMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMNmo////sshs::..................-:/-:/ooyyssssossssyssyyhyyhy::/odNMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMmds/::/shds:/-.................::....--/+osyyyyo+oosyyyyyd+:/smNMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMNhhhs/:::ohmh//:--.............-::..`..```..-/++oossooossy+:/hNMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMNdysooso///+shds+/:----------------.......`...-::/+ooossso/+omNMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMNNmdhysyys+/+oo++++sdds+//:----------................--::://///o+mMMMMMMMMMMMMMM
MMNNNNNNNNNNNNNmddhhyssos++sssyo/::+oo++oydhsoo//::------.....``........---::::://o/yNMMMMMMMMMMMMMM
yyyssyyyyyyyyyyyssoooooooo//sy+oso/:::/+oooyhysso++////:---...............-----:/+++mMMMMMMMMMMMMMMM
oooooossssyyyyssoooooooooos/:sh+/+ooo/::-:/+sssssso+++++oo+:--...............--://+hMMMMMMMMMMMMMMMM
++++++ooossssyssoo+oooooooos/:oh+////++++/////+osyyyssoo++shs/:-...........--://+shNMMMMMMMMMMMMMMMM
/////+++ooooossso+++++++++++o+:/sy+++//://///+++++osssossysssyys+::-------:+oooydNMMMMMMMMMMMMMMMMMM
///////+++ooooooo+++/+++///////::/+oso+++/+///::::::::////+ooydhyhhyssoosyhdddddmNMMMMMMMMMMMMMMMMMM
////////++++ooo+++++////////:::::::::/++o+++++++/////////++oydysyhhhhdddddddddddddmmNmNNMMMMMMMMMMMM
::://///++++++++++++///////:::::::::::::::////////////++oshhyssyyyhhhdddddddddddhhhhhhdddmmNNMMMMMMM
/:::///+//++++++///+///////:::::::::::::::::::::::///++ooooosssssyyhhhhhddhhhhhhhhhhyyyyyyhdddmMMMMM
/::://+o////+++/////////:::/:::::::::::::::::::://////++++oooooossyyyhhhhhhhhhhhhyyyssoooossyhdmNMMM
*/

/// *********** Coded by Olium_MdioxideN ***********

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define elif else if
#define pb push_back
#define mp make_pair
#define nl '\n'
#define forr(i,b,e) for(int i=b;i<=e;i++)
#define forrv(i,b,e) for(int i=b;i>=e;i--)
#define fors(i,x) for(auto i=x.begin(); i!=x.end(); i++)
#define F first
#define S second
#define mset0(x) memset(x, 0, sizeof x);
#define mset1(x) memset(x, -1, sizeof x);
#define all(x) x.begin(),x.end()
#define pqmin(x) priority_queue<x, vector<x>, greater<x> >
#define pqmax(x) priority_queue<x>
#define sortdsc(x) sort(all(x)); reverse(all(x));
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define mpii map<int,int>
#define pi 3.14159265358979323846D
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) (x*(y/__gcd(x,y)))
#define chkbit(x,p) ((x&(1LL<<p))?1:0)
#define setbit(x,p) x|=(1LL<<p)
#define clrbit(x,p) x=x&(~(1LL<<p))
#define revbit(x,p) (chkbit(x,p)?clrbit(x,p):setbit(x,p))
#define runtime() cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }

#ifndef ONLINE_JUDGE
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,
__attribute__((unused))int LINE_NUM){cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << ") ";stringstream ss;ss<<H;
cerr<<args[idx]<<" = "<<ss.str();dbg_out(args,idx+1,LINE_NUM, T...);}
#define debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define in_file freopen("input.c", "r", stdin)
#define out_file freopen("output.c", "w", stdout)
#else
#define debug(...) 0
#define in_file 0
#define out_file 0
#endif

/// * * *    Main Code Starts Now    * * *

#define MOD 10000007
#define MAX 100010
void olium();

int main()
{
    //in_file;
    //out_file;
    fast;
    int t = 1;
    //cin >> t;
    forr(i,1,t)
    {
        //cout << "Case " << i << ": ";
        olium();
    }
    return 0;
}

int n,m;
vector<int> adj[100010];

int dp[100010];

int sol(int cnode)
{
	if(dp[cnode] != -1) return dp[cnode];
	if(adj[cnode].size() == 0) return 0;
	int mx = 0;
	for(auto node : adj[cnode])
	{
		mx = max(mx, 1 + sol(node));
	}
	return dp[cnode] = mx;
}

void olium()
{
	mset1(dp);
    cin >> n >> m;
    forr(i,1,n)
    {
    	adj[i].clear();
    }
    forr(i,1,m)
    {
    	int u,v;
    	cin >> u >> v;
    	adj[u].pb(v);
    }
    int ans = 0;
    forr(i,1,n)
    {
    	ans = max(ans, sol(i));
    }
    cout << ans << nl;
}

Compiler output:
a.cc:266:4: error: redefinition of 'long long int pow_mod(long long int, long long int, long long int)'
  266 | ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }
      |    ^~~~~~~
a.cc:95:4: note: 'long long int pow_mod(long long int, long long int, long long int)' previously defined here
   95 | ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }
      |    ^~~~~~~
a.cc:269:15: error: redefinition of 'std::vector<std::__cxx11::basic_string<char> > vec_spltr(std::string)'
  269 | vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
      |               ^~~~~~~~~
a.cc:98:15: note: 'std::vector<std::__cxx11::basic_string<char> > vec_spltr(std::string)' previously defined here
   98 | vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
      |               ^~~~~~~~~
a.cc:271:6: error: redefinition of 'void dbg_out(std::vector<std::__cxx11::basic_string<char> >, int, int)'
  271 | void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,
      |      ^~~~~~~
a.cc:100:6: note: 'void dbg_out(std::vector<std::__cxx11::basic_string<char> >, int, int)' previously defined here
  100 | void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,
      |      ^~~~~~~
a.cc:273:6: error: redefinition of 'template<class Head, class ... Tail> void dbg_out(std::vector<std::__cxx11::basic_string<char> >, int, int, Head, Tail ...)'
  273 | void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
      |      ^~~~~~~
a.cc:102:6: note: 'template<class Head, class ... Tail> void dbg_out(std::vector<std::__cxx11::basic_string<char> >, int, int, Head, Tail ...)' previously declared here
  102 | void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
      |      ^~~~~~~
a.cc:291:5: error: redefinition of 'int main()'
  291 | int main()
      |     ^~~~
a.cc:120:5: note: 'int main()' previously defined here
  120 | int main()
      |     ^~~~
a.cc:306:5: error: redefinition of 'int n'
  306 | int n,m;
      |     ^
a.cc:135:5: note: 'int n' previously declared here
  135 | int n,m;
      |     ^
a.cc:306:7: error: redefinition of 'int m'
  306 | int n,m;
      |       ^
a.cc:135:7: note: 'int m' previously declared here
  135 | int n,m;
      |       ^
a.cc:307:13: error: redefinition of 'std::vector<int> adj [100010]'
  307 | vector<int> adj[100010];
      |             ^~~
a.cc:136:13: note: 'std::vector<int> adj [100010]' previously declared here
  136 | vector<int> adj[100010];
      |             ^~~
a.cc:309:5: error: redefinition of 'int dp [100010]'
  309 | int dp[100010];
      |     ^~
a.cc:138:5: note: 'int dp [100010]' previously declared here
  138 | int dp[100010];
      |     ^~
a.cc:311:5: error: redefinition of 'int sol(int)'
  311 | int sol(int cnode)
      |     ^~~
a.cc:140:5: note: 'int sol(int)' previously defined here
  140 | int sol(int cnode)
      |     ^~~
a.cc:323:6: error: redefinition of 'void olium()'
  323 | void olium()
      |      ^~~~~
a.cc:152:6: note: 'void olium()' previously defined here
  152 | void olium()
      |      ^~~~~