#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 10;
int a[N];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++)
    if (a[i] == i) ans++;
  for (int i = 0; i < n; i++)
    if (a[i] != i && a[a[i]] == i) {
      cout << ans + 2;
      return 0;
    }
  for (int i = 0; i < n; i++)
    if (a[i] != i) {
      cout << ans + 1;
      return 0;
    }
  cout << ans;
  return 0;
}
