#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100000 + 10];
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  int tmp = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == i)
      ans++;
    else if (a[a[i]] == i)
      tmp = 2;
  }
  cout << min(n, ans + tmp);
}
