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