#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  int n, a[100001];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mp[a[i]] = i;
  }
  int s = 0;
  for (int i = 0; i < n; ++i)
    if (a[i] == i) ++s;
  bool f = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == i) continue;
    int x = a[a[i]];
    if (x == i && a[i] == mp[i]) {
      f = 1;
      break;
    }
  }
  if (s < n) {
    if (f)
      s += 2;
    else
      ++s;
  }
  cout << s;
  return 0;
}
