#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, m = 0, c = 0;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    a.push_back(t);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == i)
      c++;
    else {
      if (a[a[i]] == i)
        m = 2;
      else
        m = max(m, 1);
    }
  }
  cout << c + m;
}
