#include using namespace std; struct dsu{ vector par, rank, siz; dsu(int n) : par(n, -1), rank(n, 0), siz(n, 1){} int root(int a){ if(par[a] == -1) return a; else return par[a] = root(par[a]); } bool sch(int a, int b){ return root(a) == root(b); } bool mg(int a, int b){ a = root(a), b = root(b); if(a == b) return false; if(rank[a] < rank[b]) swap(a, b); par[b] = a; if(rank[a] == rank[b]) rank[a]++; siz[a] += siz[b]; return true; } int sz(int a){ return siz[root(a)]; } }; int main() { int n, c = 0; cin >> n; dsu uf(n); for(int i = 0; i < n; i++){ int p; cin >> p; p--; if(!uf.sch(i, p)) { uf.mg(i, p); c++; } } cout << c << '\n'; return 0; }