#include <bits/stdc++.h>
using namespace std;
int n, ans = 0, a[100009];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == a[i]) ans++;
  }
  if (ans == n) {
    cout << ans;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (i != a[i] && i == a[a[i]]) {
      ans = ans + 2;
      cout << ans;
      return 0;
    }
  }
  ans = ans + 1;
  cout << ans;
  return 0;
}
