#include <bits/stdc++.h>
int main() {
  int number;
  int index[100000];
  int i, k;
  scanf("%d", &number);
  for (i = 0; i < number; i++) {
    scanf("%d", &k);
    index[k] = i;
  }
  int swap = 0;
  int result = 0;
  for (i = 0; i < number; i++) {
    if (index[i] != i) {
      if ((index[index[i]] == i) && (swap == 0)) {
        int temp = index[i];
        int tmp = index[i];
        index[i] = index[index[i]];
        index[tmp] = temp;
        swap = 1;
        result++;
      }
    } else {
      result++;
    }
  }
  if ((swap == 0) && (result != number)) {
    result++;
  }
  printf("%d\n", result);
  return 0;
}
