#include <bits/stdc++.h>
using namespace std;
const long long mx = 1e6;
int main(int argc, char const *argv[]) {
  long long i, j, a, b, c, d, n, m, t;
  cin >> n;
  long long arr[n];
  long long cnt = 0;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == i) {
      cnt++;
    }
  }
  long long mx = cnt;
  bool ok = false;
  for (i = 0; i < n; i++) {
    if (arr[i] != i) {
      if (arr[arr[i]] == i) {
        ok = true;
      }
    }
  }
  if (ok) {
    mx += 2;
  } else {
    mx += 1;
  }
  mx = min(mx, n);
  cout << mx << endl;
  return 0;
}
