#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    v.push_back(t);
  }
  int res = 0;
  bool f = 0;
  for (int i = 0; i < v.size(); i++) {
    if (i == v[i])
      res++;
    else if (i == v[v[i]])
      f = 1;
  }
  if (f == 1)
    res += 2;
  else
    res++;
  cout << min(res, n) << endl;
  return 0;
}
