#include <bits/stdc++.h>
using namespace std;
int N[100005], n;
bool vis[100005];
int main() {
  scanf("%d", &n);
  for (int ix = 0; ix != n; ix++) scanf("%d", &N[ix]);
  memset(vis, false, sizeof(vis));
  bool Do = false;
  for (int ix = 0; ix != n; ix++) {
    if (N[ix] == ix) continue;
    if (N[N[ix]] == ix && !Do) {
      vis[N[ix]] = true;
      vis[ix] = true;
      swap(N[N[ix]], N[ix]);
      Do = true;
    }
  }
  for (int ix = 0; ix != n; ix++) {
    if (N[ix] == ix) continue;
    if (!vis[N[ix]] && !vis[ix] && !Do) {
      vis[N[ix]] = true;
      vis[ix] = true;
      swap(N[N[ix]], N[ix]);
      Do = true;
    }
  }
  int ans = 0;
  for (int ix = 0; ix != n; ix++)
    if (N[ix] == ix) ans++;
  cout << ans << endl;
}
