#include <algorithm>#include <iostream>#include <cstring>#include <iomanip>#include <cstdlib>#include <string>#include <vector>#include <cstdio>#include <cmath>#include <map>using namespace std;int n, m;vector <int> e[101];bool visited[101];int dfn[101], low[101];vector <int> S;int idx;int DEL;int maxSCC;int res;void dfs(int cur){ visited[cur] = true; dfn[cur] = low[cur] = ++idx; S.push_back(cur); for(int i = 0; i < e[cur].size(); i++) { int t = e[cur][i]; if(t == DEL) continue; if(!visited[t]) { dfs(t); low[cur] = min(low[cur], low[t]); } else low[cur] = min(low[cur], dfn[t]); } if(dfn[cur] == low[cur]) { int thisSCC = 0; while(true) { int t = S[S.size()-1]; S.pop_back(); thisSCC ++; if(t == cur) { maxSCC = max(maxSCC, thisSCC); break; } } }}void tarjan(){ S.clear(); maxSCC = 0; memset(visited, false, sizeof(visited)); visited[DEL] = true; for(int i = 0; i < n; i++) if(!visited[i]) { idx = 0; dfs(i); } res = maxSCC; if(res == 1) res = 0;}int MAIN(){ while(cin >> n >> m) { for(int i = 0; i < n; i++) e[i].clear(); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; e[a].push_back(b); } int ans = 10000; for(int i = 0; i < n; i++) { DEL = i; tarjan(); ans = min(ans, res); } cout << ans << endl; } return 0;}int main(){ ios :: sync_with_stdio(false); return MAIN();}


