#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int count = 0;
  long long int max = 0;
  bool flag = 0;
  for (long long int i = 0; i < n; i++) {
    if (arr[i] == i)
      count++;
    else {
      if ((arr[arr[i]] == i) || flag == 1) {
        max = 2;
        flag = 1;
      } else
        max = 1;
    }
  }
  long long int answer = count + max;
  cout << answer;
}
