#include <bits/stdc++.h>
using namespace std;
inline uint64_t in() {
  char c;
  register uint64_t n = 0;
  c = getchar();
  while (c != '-' && !(c >= '0' && c <= '9')) c = getchar();
  while (c >= '0' && c <= '9') {
    n = 10 * n + c - '0';
    c = getchar();
  }
  return n;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, c = 0, p = 0;
  n = in();
  int a[n];
  for (int i = 0; i < n; ++i) {
    a[i] = in();
  }
  for (int i = n; i; i--) {
    if (a[i - 1] == i - 1) {
      c++;
    } else {
      if (a[a[i - 1]] == i - 1 && !p) {
        p++;
      }
    }
  }
  if (c == n) {
    cout << c;
    return 0;
  }
  if (n > 1) {
    if (c) {
      if (p)
        cout << c + 2;
      else
        cout << c + 1;
    } else if (p)
      cout << 2;
    else
      cout << 1;
  } else {
    if (a[0] == 0)
      cout << 1;
    else
      cout << 0;
  }
}
