#include #include #include using namespace std; using ll = long long; int main(void){ int n; cin >> n; vector a(n); for(auto&x:a) cin >> x, x--;; vector col(n); int ans=0; auto dfs=[&](auto dfs, int now, vector& path)->void { path.push_back(now); if(col[now]==0){ col[now]=1; dfs(dfs, a[now], path); } else{ if(col[now]==1) ans++; for(auto p:path) col[p]=2; return; } }; for(int i=0; i p; dfs(dfs, i, p); } cout << ans << endl; return 0; }