#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector p(n); vector is_root(n, true); for (int i = 0; i < n; i++) { cin >> p[i]; p[i]--; if (p[i] >= 0) { is_root[p[i]] = false; } } vector ans; for (int i = 0; i < n; i++) { if (!is_root[i]) { continue; } if (p[i] != -1 && p[p[i]] != -1) { ans.push_back(p[p[i]]); } } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); cout << ans.size() << endl; }