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