#include <bits/stdc++.h>
using namespace std;
struct point {
  int x;
  int y;
};
bool operator<(const point &a, const point &b) { return (a.x < b.x); }
int compare(const void *a, const void *b) { return (*(int *)a - *(int *)b); }
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int tc;
int main() {
  int n, i, cnt = 0;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i == a[i]) cnt++;
  }
  if (cnt >= n - 2) {
    cout << n << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    if (i != a[i] && a[a[i]] == i) {
      cnt += 2;
      cout << cnt << endl;
      return 0;
    }
  }
  cout << ++cnt << endl;
  return 0;
}
