#include using namespace std; struct dsu{ vector par, sz; dsu(int n) : par(n), sz(n, 1){ iota(par.begin(), par.end(), 0); } int root(int x){ if (x == par[x]) return par[x]; return par[x] = root(par[x]); } void merge(int x, int y){ x = root(x), y = root(y); if (x == y) return; if (sz[x] < sz[y]) swap(x, y); sz[x] += sz[y], par[y] = x; } bool same(int x, int y){ return root(x) == root(y); } int size(int x){ return sz[root(x)]; } }; int main(){ int N; cin >> N; dsu uf(N); for (int i = 0; i < N; i++){ int x; cin >> x; uf.merge(i, x-1); } set roots; for (int i = 0; i < N; i++) roots.insert(uf.root(i)); cout << roots.size() << endl; }