#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int res = 0;
  bool yes = false;
  for (int i = 0; i < n; i++) {
    if (a[i] == i)
      res++;
    else if (a[a[i]] == i)
      yes = true;
  }
  if (yes)
    res += 2;
  else if (res < n)
    res++;
  cout << res << endl;
}
