#include <bits/stdc++.h>
using namespace std;
template <class T>
string toStr(const T &x) {
  stringstream s;
  s << x;
  return s.str();
}
template <class T>
int toInt(const T &x) {
  stringstream s;
  s << x;
  int r;
  s >> r;
  return r;
}
int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int main() {
  int n, tmp;
  cin >> n;
  vector<int> v(n);
  int ans = 0;
  map<int, int> mapa1, mapa2;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    mapa1[i] = v[i];
    mapa2[v[i]] = i;
  }
  int f = false, f2 = false;
  for (int i = 0; i < n; ++i) {
    if (i == mapa2[i])
      ans++;
    else {
      f2 = true;
      if (mapa1[i] == mapa2[i]) f = true;
    }
  }
  if (!f2) {
    cout << n << endl;
    return 0;
  }
  if (f2 && f)
    ans += 2;
  else if (ans && !f)
    ans++;
  else if (!f && f2 && !ans)
    ans++;
  cout << ans << endl;
  return 0;
}
