#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, cnt = 0, x = 1, y = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == i) {
      cnt++;
    } else if (a[a[i]] == i) {
      y = 1;
      x = 2;
    } else {
      y = 1;
    }
  }
  if (y) {
    cnt += x;
  }
  cout << cnt << "\n";
  return 0;
}
