#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, fixedPoint = 0;
  bool check = true;
  cin >> n;
  int arr[n + 5];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 0; i < n; ++i) {
    if (arr[i] == i) {
      fixedPoint++;
    } else if (arr[i] != i && arr[i] < n && check == true) {
      int j = arr[i];
      if (arr[j] == i) {
        swap(arr[i], arr[j]);
        fixedPoint++;
        check = false;
      }
    }
  }
  if (fixedPoint < n && check == true) {
    cout << ++fixedPoint;
  } else {
    cout << fixedPoint;
  }
  return 0;
}
