#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
long long rll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int mas[100500];
int p[100500];
void solve() {
  int n = ri();
  int res = 0;
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    mas[i] = ri(), res += mas[i] == i;
    p[mas[i]] = i;
  }
  int t = res;
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    if (mas[i] == i) continue;
    int a = p[i];
    int b = mas[a];
    int temp = t + 1;
    if (a == mas[i]) temp++;
    if (b == a) temp--;
    res = max(res, temp);
  }
  cout << res << endl;
}
int main() {
  solve();
  return 0;
}
