#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  vector<int> v;
  int count[100001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    count[i] = a;
  }
  int count1 = 0;
  for (int i = 0; i < n; i++) {
    if (count[i] == i) count1++;
  }
  if (count1 == n) {
    cout << count1;
    return 0;
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (count[i] != i) {
      int val = count[i];
      int val2 = count[val];
      if (val2 == i) {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 1) {
    cout << count1 + 2;
  } else {
    cout << count1 + 1;
  }
  return 0;
}
