#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_set>
using namespace std;
#define int long long
const int N = 1e5 + 10, M = 3e5 + 10;
int h[N], h1[N], h2[N], e[M], ne[M], idx;
int dfn[N], low[N], stk[N], id[N], siz[N], top, timetamp, cnt;
bool st[N], inq[N], used[N];
int dist1[N], dist2[N];
void add(int h[], int a, int b)
{
ne[idx] = h[a], e[idx] = b, h[a] = idx++;
}
void tarjan(int u)
{
dfn[u] = low[u] = ++timetamp;
stk[++top] = u, st[u] = true;
for(int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if(!dfn[j])
{
tarjan(j);
low[u] = min(low[u], low[j]);
}
else if(st[j]) low[u] = min(low[u], dfn[j]);
}
if(dfn[u] == low[u])
{
int y;
cnt++;
do
{
y = stk[top--];
st[y] = false;
id[y] = cnt;
siz[cnt]++;
}while(y != u);
}
}
void spfa(int h[], int dist[])
{
queue<int> q;
q.push(id[1]), dist[id[1]] = siz[id[1]];
while(q.size())
{
int t = q.front();
q.pop(), inq[t] = false;
for(int i = h[t]; ~i; i = ne[i])
{
int j = e[i];
if(dist[j] < dist[t] + siz[j])
{
dist[j] = dist[t] + siz[j];
if(!inq[j])
{
inq[j] = true;
q.push(j);
}
}
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
memset(h, -1, sizeof h);
memset(h1, -1, sizeof h1);
memset(h2, -1, sizeof h2);
int n, m;
cin >> n >> m;
unordered_set<long long> s;
for(int i = 1; i <= m; i++)
{
int a, b;
cin >> a >> b;
long long hash = a * 1000000ll + b;
if(s.count(hash)) continue;
s.insert(hash);
add(h, a, b);
}
for(int i = 1; i <= n; i++) if(!dfn[i]) tarjan(i);
for(int i = 1; i <= n; i++)
{
for(int j = h[i]; ~j; j = ne[j])
{
int k = e[j];
if(id[i] == id[k]) continue;
add(h1, id[i], id[k]), add(h2, id[k], id[i]);
}
}
spfa(h1, dist1), spfa(h2, dist2);
int ans = siz[id[1]];
for(int u = 1; u <= cnt; u++)
{
if(dist2[u] < 0) continue;
for(int j = h1[u]; ~j; j = ne[j])
{
int v = e[j];
if(dist1[v] < 0) continue;
ans = max(ans, dist2[u] + dist1[v] - siz[id[1]]);
}
}
cout << ans;
}