#include <bits/stdc++.h>
using namespace std;
int n, a[100005], d[100005];
int main() {
  cin >> n;
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    d[a[i]] = i;
    c += (a[i] == i);
  }
  int r = c;
  if (c < n)
    for (int i = 0; i < n; i++) {
      if (a[i] == i) continue;
      r = max(r, c + 1 + (d[i] == a[i]));
    }
  cout << r;
}
