#include using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; struct DSU { std::vector f; DSU() {} DSU(int n) { init(n); } void init(int n) { f.resize(n); std::iota(f.begin(), f.end(), 0); } int find(int x) { while (x != f[x]) { x = f[x] = f[f[x]]; } return x; } bool merge(int x, int y) { x = find(x); y = find(y); if (x == y) { return false; } f[y] = x; return true; } }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; DSU dsu(N); int cc = N; for (int i = 0; i < N; i++) { int x; std::cin >> x; x--; if (dsu.merge(i, x)) cc--; } std::cout << N - cc << '\n'; return 0; }