#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
template <class T>
bool get_max(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
int n;
int a[100010];
int pos[100010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == i) ++ans;
    pos[a[i]] = i;
  }
  bool flag = false;
  for (int i = 0; i < n; ++i) {
    if (a[i] != i && pos[i] == a[i]) {
      flag = true;
      break;
    }
  }
  if (ans != n) {
    if (flag)
      ans += 2;
    else
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}
