#include <bits/stdc++.h>
using namespace std;
char inp[1000000];
stack<char> rem;
int main() {
  int n, a[100000], i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  int flag = 0, cnt = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == i) {
      cnt++;
    } else if (a[a[i]] == i) {
      flag = 1;
    }
  }
  if (cnt == n)
    cout << n;
  else if (flag == 0)
    cout << cnt + 1;
  else
    cout << cnt + 2;
  return 0;
}
