#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int n, x[100001], res = 0;
  bool isdop = false;
  cin >> n;
  memset(x, -1, sizeof(x));
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] == i)
      res++;
    else {
      if (!isdop && x[x[i]] == i) isdop = true;
    }
  }
  if (isdop)
    res += 2;
  else if (res != n)
    res++;
  cout << res << endl;
  return 0;
}
