#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cnt = 0, f = 0, t = 0;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; ++i) {
    if (i == arr[i])
      ++cnt;
    else if (i == arr[arr[i]] && f == 0) {
      cnt = cnt + 2;
      f = 1;
      t = 1;
    } else
      t = 1;
  }
  if (f == 0 && t == 1) ++cnt;
  cout << cnt;
  return 0;
}
