#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int idx[1000000];
bool visited[1000000];
int main() {
  memset(visited, false, sizeof(visited));
  int n;
  cin >> n;
  int add = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == a[i]) {
      ans++;
      visited[i] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      if (!visited[a[i]]) {
        add = 1;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      if (a[a[i]] == i && !visited[a[i]]) {
        add = 2;
        break;
      }
    }
  }
  cout << ans + add << endl;
  return 0;
}
