#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];
  vector<int> ind;
  int num = 0, add = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == i)
      ++num;
    else if (a[a[i]] == i)
      add = 2;
  }
  if (!add) add = 1;
  if (num == n) add = 0;
  cout << num + add << endl;
  return 0;
}
