#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
template <typename T>
void print(T AA[], long long int nn) {
  for (long long int ii = 0; ii < nn; ii += 1) {
    cout << AA[ii] << " ";
  }
  cout << "\n";
}
template <typename T>
inline void print(T nn) {
  cout << nn << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int A[n];
  for (long long int i = 0; i < n; i += 1) cin >> A[i];
  bool swap = false;
  long long int ans = 0;
  for (long long int i = 0; i < n; i += 1) {
    if (A[i] == i)
      ans += 1;
    else {
      if (!swap and A[A[i]] == i) {
        ans += 1;
        A[A[i]] = A[i];
        A[i] = i;
        swap = true;
      }
    }
  }
  if (ans == n) {
    print(ans);
    return 0;
  }
  if (!swap) ans += 1;
  print(ans);
  return 0;
}
