#include <bits/stdc++.h>
using namespace std;
int n, a[100010], Ans, p[100010], Re;
bool E[100010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i)
      Ans++, E[i] = true;
    else
      Re++;
    p[i] = a[i];
  }
  bool flag = true;
  for (int i = 0; i < n; i++)
    if ((!E[i]) && (p[a[i]] == i)) {
      Ans += 2;
      flag = false;
      break;
    }
  if ((flag) && (Re)) Ans++;
  printf("%d", Ans);
}
