#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  long long i;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int flag = 1;
  int ans = 0;
  int min = a[0];
  for (i = 0; i < n; i++) {
    if (min < a[i]) min = a[i];
    if (a[i] == i)
      ans++;
    else if (flag == 1) {
      if (a[a[i]] < n - 1) {
        if (i == a[a[i]]) {
          ans += 2;
          flag = 0;
        }
      }
    }
  }
  if (flag == 0)
    cout << ans;
  else if (ans > 0) {
    if (ans < n)
      cout << ans + 1;
    else
      cout << ans;
  } else if (min > n - 1)
    cout << ans;
  else if (min <= n - 1 && ans == 0)
    cout << 1;
}
