#include <bits/stdc++.h>
using namespace std;
bool prime[1000005];
int primes[1000005], total_primes;
template <class T>
T powe(T x, T n) {
  if (n == 0) return 1;
  T r = 1, y = x;
  while (n > 1) {
    if (n & 1) r *= y;
    y *= y;
    n /= 2;
  }
  r *= y;
  return r;
}
template <class T>
T modpow(T x, T n) {
  if (n == 0) return 1;
  T r = 1, y = x;
  while (n > 1) {
    if (n & 1) {
      r *= y;
      r %= 1000000007;
    }
    y *= y;
    y %= 1000000007;
    n /= 2;
  }
  r *= y;
  r %= 1000000007;
  return r;
}
template <class T>
T gcd(T a, T b) {
  while (b > 0) {
    a ^= b;
    b ^= a;
    a ^= b;
    b %= a;
  }
  return a;
}
void seive() {
  int i, j;
  memset(prime, 1, sizeof(prime));
  prime[0] = prime[1] = false;
  for (i = 4; i < 1000005; i += 2) prime[i] = false;
  for (i = 3; i * i < 1000005; i += 2)
    if (prime[i])
      for (j = i * i; j < 1000005; j += (i << 1)) prime[j] = false;
}
void storeprimes() {
  int i, j = 0;
  for (i = 0; i < 1000005; i++)
    if (prime[i]) primes[j++] = i;
  total_primes = j;
}
int main() {
  int n, cnt = 0, i, x = 0;
  int a[100005];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n; i++)
    if (a[i] == i) cnt++;
  for (i = 0; i < n; i++)
    if (a[i] != i) {
      if (a[a[i]] != i)
        x = 1;
      else
        x = 2;
      if (x == 2) break;
    }
  printf("%d", cnt + x);
  printf("\n");
  return 0;
}
