#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, ans = 0;
  bool check = false;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (a[i] == i) ans++;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != i && a[a[i]] == i) {
      check = true;
      ans += 2;
      break;
    }
  }
  if (ans != n && !check) ans++;
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
