#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector p(n); vector used(n, false); for(int i = 0; i < n; i++){ cin >> p[i]; p[i]--; if(p[i] == -1) continue; used[p[i]] = true; } int ans = 0; vector B(n); for(int i = 0; i < n; i++){ if(used[i]) continue; if(p[i] == -1) continue; if(p[p[i]] == -1) continue; B[p[p[i]]] = true; } cout << count(B.begin(), B.end(), true) << '\n'; }