import std.stdio, std.algorithm, std.array, std.conv, std.typecons; alias Set = bool[3 * 10^^5]; void main() { readln; auto P = readln.split.to!(ulong[]); P = [0UL] ~ P; auto N = P.length-1; auto set = new bool[N+1]; foreach (p; P) { set[p] = true; } auto ans = new bool[N+1]; foreach (i; 1 .. N+1) if (!set[i]){ if (P[i] != 0 && P[P[i]] != 0) ans[P[P[i]]] = true; } writeln(ans.count(true)); }