#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  long long int i, x, count;
  count = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int flag = 0;
  for (i = 0; i < n; i++) {
    if (a[i] != i) {
      flag = 1;
      break;
    }
  }
  if (flag != 1) {
    cout << n << "\n";
  } else {
    flag = 0;
    for (i = 0; i < n; i++) {
      if (a[i] != i) {
        if (a[a[i]] == i) {
          x = a[a[i]];
          a[a[i]] = a[i];
          a[i] = x;
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1) {
      for (i = 0; i < n; i++) {
        if (a[i] == i) {
          count++;
        }
      }
      cout << count << "\n";
    } else {
      for (i = 0; i < n; i++) {
        if (a[i] == i) {
          count++;
        }
      }
      cout << (count + 1) << "\n";
    }
  }
  return 0;
}
