#include <bits/stdc++.h>
using namespace std;
int solve(int n, int a[]) {
  int count = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == i) {
      ++count;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] != i && a[a[i]] == i) {
      return count + 2;
    }
  }
  return min(count + 1, n);
}
int main() {
  int n;
  int a[100000];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cout << solve(n, a) << endl;
  return 0;
}
