#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int tab[n];
  long long s = 0;
  for (int i = 0; i < n; i++) {
    cin >> tab[i];
    if (i == tab[i]) {
      s++;
      tab[i] = -1;
    }
  }
  bool bo = false;
  for (int i = 0; i < n; i++) {
    if (tab[i] != -1) {
      if (tab[tab[i]] == i) {
        s += 2;
        bo = false;
        break;
      }
      bo = true;
    }
  }
  if (bo) s++;
  cout << s;
}
