#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  bool b[n];
  fill(b, b + n, false);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  for (int i = 0; i < n; ++i) b[a[i]] = true;
  long long res = 0, flag = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] == i) {
      res++;
      continue;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == i)
      continue;
    else if (a[a[i]] == i) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    cout << res + 2 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (res != n) {
      if (b[i] == true) {
        cout << res + 1;
        return 0;
      }
    }
  }
  cout << res << endl;
}
