#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int *arr = new int[n];
  for (size_t i = 0; i < n; i++) scanf("%d", &arr[i]);
  int res = 0;
  int t = 0;
  for (size_t i = 0; i < n; i++) {
    if (arr[i] == i)
      res++;
    else {
      if (arr[arr[i]] == i)
        t = 2;
      else
        t = t < 2 ? 1 : 2;
    }
  }
  printf("%d", res + t);
  return 0;
}
