#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
const double PI = 3.14;
void solution();
int main() { solution(); }
void solution() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  set<int> b;
  long long int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == i) {
      c++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != i) {
      if (a[a[i]] == i) {
        c = c + 2;
        cout << c << "\n";
        return;
      }
    }
  }
  if (c < n)
    cout << c + 1 << "\n";
  else
    cout << c << "\n";
}
