public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] num = new int[n];
        int add = 0;
        int now = 0;
        for (int i = 0; i < n; i++) {
            num[i] = in.nextInt();
            if (num[i] == i) {
                now++;
            }
        }
        for (int i = 0; i < n; i++) {
            if (num[i] != i && num[num[i]] != num[i]) {
                if (i == num[num[i]]) {
                    add = 2;
                    break;
                } else {
                    add = 1;
                }
            }
        }
        System.out.println(now + add);
    }