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