class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n + 1) self.size = [1] * (n + 1) def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same_check(self, x, y): return self.find(x) == self.find(y) n = int(input()) p = list(map(int, input().split())) uf = UnionFind(n) for i in range(n): uf.unite(i, p[i] - 1) st = set() ans = 0 for i in range(n): i = uf.find(i) if i in st: continue st.add(i) ans += 1 print(ans)