#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vii = vector<ii>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vs>;
int main() {
  iostream::sync_with_stdio(false);
  int n;
  cin >> n;
  vi v(n);
  for (auto(i) = 0; (i) < (n); ++(i)) cin >> v[i];
  int ret = 0;
  int ss = 0;
  for (auto(i) = 0; (i) < (n); ++(i)) {
    if (v[i] == i) {
      ++ret;
      continue;
    }
    if (v[v[i]] == i)
      ss = max(ss, 2);
    else
      ss = max(ss, 1);
  }
  cout << ret + ss;
  cout << "\n";
  return 0;
}
