#include <bits/stdc++.h>
using namespace std;
int arr[(int)1e5 + 5];
int pos[(int)1e5 + 5];
int vis[(int)1e5 + 5];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> arr[i];
    pos[arr[i]] = i;
  }
  bool swapped = false;
  for (int i = 0; i < N; ++i) {
    if (arr[i] == i) {
      continue;
    } else {
      if (swapped) continue;
      if (pos[i] == arr[i]) {
        int temp = arr[i];
        arr[i] = i;
        arr[pos[i]] = temp;
        swapped = true;
      }
    }
  }
  if (!swapped) {
    for (int i = 0; i < N && !swapped; ++i) {
      if (arr[i] == i) {
        continue;
      } else {
        swap(arr[i], arr[pos[i]]);
        swapped = true;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; ++i)
    if (arr[i] == i) cnt++;
  cout << cnt << endl;
  return 0;
}
