#include <bits/stdc++.h>
using namespace std;
int main() {
  long a[100005], n;
  int x = 0;
  cin >> n;
  long i, count = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == i) {
      count++;
      a[i] = 0;
    }
  }
  if (count == n) {
    cout << count << "\n";
    return 0;
  }
  for (i = 0; i < n - 1; i++) {
    if (a[i] != 0 && a[a[i]] == i) {
      x = 2;
      break;
    }
  }
  if (x == 2) {
    cout << count + 2 << "\n";
  } else
    cout << count + 1 << "\n";
}
