#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  while (scanf("%d", &num) == 1) {
    vector<int> v(num + 5);
    vector<int> mark(num + 5);
    int count = 0;
    for (int i = 0; i < num; i++) {
      scanf("%d", &v[i]);
      mark[v[i]] = i;
    }
    int flag = 0;
    for (int i = 0; i < num; i++) {
      if (v[i] != i) {
        if (mark[i] == v[i]) flag = 1;
      } else if (v[i] == i)
        count++;
    }
    if (flag == 0 && count == num)
      printf("%d\n", count);
    else if (flag == 0)
      printf("%d\n", count + 1);
    else
      printf("%d\n", count + 2);
  }
  return 0;
}
