#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  int fp = 0;
  int t = 0;
  int r = -1;
  for (int i = 0; i < n; ++i) {
    if (v[i] == i || i == r) {
      fp++;
      continue;
    }
    if (v[v[i]] == i && r < 0) {
      r = v[i];
      fp++;
    }
  }
  if (fp < n && r < 0) fp++;
  cout << fp << "\n";
  return 0;
}
