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