#include <bits/stdc++.h>
using namespace std;
int n, ans = 0, a[210001], x, y;
int main() {
  bool bo = false;
  scanf("%d\n", &n);
  for (int i = 0; i <= n - 1; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) ans++;
  }
  for (int i = 0; i <= n - 1; i++) {
    if (a[i] != i && a[i] < n) {
      x = a[i];
      y = a[x];
      if (x == a[y] && y == i) {
        ans = ans + 2;
        bo = true;
        break;
      }
    }
  }
  if (!bo)
    for (int i = 0; i <= n - 1; i++) {
      if (a[i] != i && a[i] < n) {
        x = a[i];
        if (x != i) {
          ans = ans + 1;
          break;
        }
      }
    }
  cout << ans;
  return 0;
}
