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