#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(const T &a) {
  return a * a;
}
int n, x, b[100001], boo, ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) b[i] = -1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x == i) ans++;
    b[x] = i;
    if (b[i] == x && i != x && boo == 0) {
      boo = 2;
      ans += 2;
    }
    if (b[i] == x && i != x && boo == 1) {
      boo = 2;
      ans++;
    }
    if (b[i] != i && i != x && boo == 0) {
      boo = 1;
      ans++;
    }
  }
  printf("%d\n", ans);
}
