#include using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; vector p(n), in(n, 0); for (int &x : p) cin >> x; for (int x : p) { if (x > 0) in[x - 1]++; } vector ans(n, false); for (int i = 0; i < n; i++) { if (in[i] == 0) { int res = i; for (int j = 0; j < 2; j++) { if (res >= 0) res = p[res] - 1; } if (res >= 0) ans[res - 1] = true; } } cout << count(ans.begin(), ans.end(), true) << "\n"; return 0; }