#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector P(N); rep(i, 0, N) { cin >> P[i]; --P[i]; } vector ok(N, true); rep(i, 0, N) if (P[i] != -1) ok[P[i]] = false; vector check(N, false); rep(q, 0, N) if (ok[q]) { int p = P[q]; if (p != -1) { int i = P[p]; if (i != -1) check[i] = true; } } int ans = 0; rep(i, 0, N) if (check[i]) ++ans; cout << ans << '\n'; }