#include <bits/stdc++.h>
using namespace std;
long long m = 1000000007;
int main() {
  int n, i, ans, x;
  bool b = 0;
  cin >> n;
  int arr[n];
  ans = 0;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == i) ans++;
  }
  for (i = 0; i < n; i++) {
    x = arr[i];
    if (x != i && arr[x] == i) {
      b = 1;
      break;
    }
  }
  if (b)
    ans += 2;
  else if (ans != n)
    ans++;
  cout << ans << endl;
  return 0;
}
