#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, temp, count = 0, found = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp == i)
      ++count;
    else if (temp < i && a[temp] == i)
      found = 2;
    else if (found != 2)
      found = 1;
    a[i] = temp;
  }
  cout << count + found << endl;
  return 0;
}
