#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, m, n;
  int A[200000] = {0}, count = 0, flag = 0, B[200000] = {0};
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &m);
    if (m != i) {
      A[i] = m;
      B[i] = 1;
    } else
      count++;
  }
  for (i = 0; i < n; i++) {
    if (i == A[A[i]] && B[i] == 1) {
      flag = 1;
      break;
    }
  }
  if (count == n)
    printf("%d\n", count);
  else if (flag == 1)
    printf("%d\n", count + 2);
  else
    printf("%d\n", count + 1);
  return 0;
}
