#include <bits/stdc++.h>
using namespace std;
struct desc_fir {
  bool operator()(const std::pair<long long, long long> &left,
                  const std::pair<int, int> &right) {
    return left.first > right.first;
  }
};
int main() {
  long long n, i, j, k, m, t, s;
  vector<long long> v;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> j;
    v.push_back(j);
  }
  bool isit = false;
  s = 0;
  for (i = 0; i <= n - 1; i++)
    if (i == v[i]) s++;
  if (s != n) {
    for (i = 0; i <= n - 1; i++) {
      if (v[i] != i)
        if (v[v[i]] == i) {
          s += 2;
          isit = true;
          break;
        }
    }
    if (!isit) s++;
  }
  cout << s << endl;
  return 0;
}
