#include
#include
#include
#include
using namespace std;
vector graph[50001];
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++) {
int x;
cin >> x;
x--;
graph[i].push_back(x);
}
vector visited_bfs(n, false);
int res = 0;
for(int i = 0; i < n; i++) {
if(!visited_bfs[i]) {
queue q;
q.push(i);
vector visited(n, false);
visited[i] = true;
int nodes = 1;
while(!q.empty()) {
int node = q.front();
q.pop();
for(int j = 0; j < (int) graph[node].size(); j++) {
int neighbour = graph[node][j];
if(!visited[neighbour]) {
visited[neighbour] = true;
visited_bfs[neighbour] = true;
q.push(neighbour);
nodes++;
res = max(res, nodes);
}
}
}
}
}
cout << res << endl;
return 0;
}