#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const int N = 3e5;
int a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int sum = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == i) {
      sum++;
      continue;
    }
    if (i == a[a[i]]) flag = 1;
  }
  if (flag)
    sum += 2;
  else
    sum++;
  if (sum > n) sum = n;
  cout << sum << endl;
  return 0;
}
