#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, ans = 0;
int dat[N];
int fa[N];
int main() {
  cin >> n;
  memset(fa, -1, sizeof(fa));
  for (int i = 0; i < n; ++i) {
    cin >> dat[i];
    if (dat[i] == i)
      ans++;
    else
      fa[i] = dat[i];
  }
  int flag = 0;
  int flag2 = 0;
  for (int i = 0; i < n; ++i) {
    if (fa[i] == -1) continue;
    if (i == dat[fa[i]])
      flag = 1;
    else
      flag2 = 1;
  }
  if (flag)
    ans += 2;
  else if (flag2)
    ans += 1;
  cout << ans << endl;
  return 0;
}
