#include <bits/stdc++.h>
using namespace std;
int a;
int b[100002];
int pos[100002];
int main() {
  memset(b, 0, sizeof(b));
  memset(pos, 0, sizeof(pos));
  scanf("%d", &a);
  int coun = 0;
  for (int i = 0; i < a; i++) {
    scanf("%d", &b[i]);
    pos[b[i]] = i;
    if (b[i] == i) coun++;
  }
  if (coun == a) {
    printf("%d\n", coun);
    return 0;
  }
  for (int i = 0; i < a; i++) {
    if (b[i] != i) {
      if (pos[i] == b[i]) {
        coun += 2;
        printf("%d\n", coun);
        return 0;
      }
    }
  }
  printf("%d\n", coun + 1);
  return 0;
}
