#include using namespace std; using ll = long long; #define dbg(a) cerr << #a << ": " << a << "\n" struct DSU { vector par, sz; DSU(int n): par(n), sz(n,1) { iota(par.begin(), par.end(), 0); } int find(int v) { return (par[v] == v)? v: (par[v] = find(par[v])); } void unite(int u, int v) { u = find(u), v = find(v); if(u != v){ if(sz[u] < sz[v]) { swap(u, v); } par[v] = u; sz[u] += sz[v]; } } int size(int v) { return sz[find(v)]; } bool same_set(int u, int v) { return find(u) == find(v); } }; void solve() { int n; cin >> n; DSU dsu(n); for (int i = 0; i < n; ++i) { int pi; cin >> pi; pi--; dsu.unite(i, pi); } int ans = n; for (int i = 0; i < n; ++i) { ans -= (dsu.find(i) == i); } cout << ans << "\n"; } int main(){ ios::sync_with_stdio(0), cin.tie(0); int tc = 1; for (int t = 1; t <= tc; ++t) { solve(); } }