#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j;
  cin >> t;
  int arr[t];
  int count = 0;
  int flag[t];
  for (i = 0; i < t; i++) flag[i] = 0;
  for (i = 0; i < t; i++) {
    cin >> arr[i];
    if (i == arr[i]) {
      count++;
      flag[i] = 1;
    }
  }
  int c = 0;
  int flag1 = 0;
  int f2 = 0;
  if (count == t) flag1 = 1;
  int max = 0;
  if (flag1 == 1)
    cout << count << endl;
  else {
    for (i = 0; i < t; i++) {
      if (flag[i] == 0) {
        if (arr[arr[i]] == i && (arr[arr[arr[i]]] == arr[i])) {
          f2 = 1;
        }
        if (f2 == 1) break;
      }
    }
    if (f2 == 1)
      cout << count + 2 << endl;
    else
      cout << count + 1 << endl;
  }
  return 0;
}
