#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, sum = 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int a = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] != i) {
      if (v[v[i]] == i)
        a = 2;
      else if (a != 2)
        a = 1;
    } else
      sum++;
  }
  cout << sum + a;
}
