#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int a[N];
int main() {
  int n;
  cin >> n;
  int cn = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i == a[i]) ++cn;
  }
  if (cn == n || cn == n - 2) {
    cout << n;
    return 0;
  }
  bool has = false;
  for (int i = 0; i < n; ++i) {
    if (a[i] == i) continue;
    if (a[a[i]] == i) {
      cout << cn + 2;
      return 0;
    }
  }
  cout << cn + 1;
  return 0;
}
