#include <bits/stdc++.h>
using namespace std;
int a[100001];
bool flag[100001];
int main() {
  int tc;
  scanf("%d", &tc);
  for (int i = 0; i < tc; i++) {
    scanf("%d", &a[i]);
    flag[a[i]] = true;
  }
  int him = 0, ctr = 0;
  ;
  for (int i = 0; i < tc; i++) {
    if (i == a[i])
      ctr++;
    else if (a[a[i]] == i and him == 0) {
      ctr += 2;
      him = 1;
    }
  }
  if (him == 1) {
    printf("%d\n", ctr);
    return 0;
  }
  if (ctr != tc)
    printf("%d\n", ctr + 1);
  else
    printf("%d\n", ctr);
  return 0;
}
