#include <bits/stdc++.h>
using namespace std;
int main() {
  int tam;
  scanf("%d", &tam);
  vector<int> pos(tam, -1);
  int i, aux, cont = 0, mod = 0;
  for (i = 0; i < tam; i++) {
    scanf("%d", &aux);
    pos[aux] = i;
  }
  for (i = 0; i < tam; i++) {
    if (i == pos[i])
      cont++;
    else if (mod == 0) {
      if (pos[pos[i]] == i) {
        cont += 2;
        mod = 1;
      }
    }
  }
  if (mod == 0)
    printf("%d", min(cont + 1, tam));
  else
    printf("%d", cont);
  return 0;
}
