#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, k, t, r;
  cin >> n;
  k = 0;
  t = 1;
  int tab[n];
  for (i = 0; i < n; i++) {
    cin >> tab[i];
    if (tab[i] == i) {
      k++;
    }
  }
  for (i = 0; i < n; i++) {
    if ((tab[tab[i]] == i) && (tab[i] != i)) {
      t = 2;
    }
  }
  r = k + t;
  if (k == n) {
    cout << k;
  } else {
    cout << r;
  }
  return 0;
}
