#include <bits/stdc++.h>
using namespace std;
int in[1000010], check[100010];
int main() {
  int cnt = 0, i, t;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> in[i];
    if (in[i] == i) {
      cnt++;
    }
  }
  int mark = 0;
  for (i = 0; i < t; i++) {
    if (in[i] != i) {
      if (in[in[i]] == i) {
        cnt += 2;
        mark = 1;
        break;
      }
    }
  }
  if (mark == 0 && cnt != t) cnt++;
  cout << cnt << endl;
}
