#include <bits/stdc++.h>
int a[100000];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int ans = 0;
  int temp = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == i)
      ans++;
    else if (a[a[i]] == i)
      temp = 2;
  }
  if (temp == 0) {
    if (ans < n)
      printf("%d\n", ans + 1);
    else
      printf("%d\n", ans);
  } else
    printf("%d\n", ans + 2);
  return 0;
}
