1import java.io.*;
2import java.math.*;
3import java.util.*;
4
5public class Swap {
6 static int minimumSwaps(int[] arr) {
7 int swap=0;
8 boolean visited[]=new boolean[arr.length];
9
10 for(int i=0;i<arr.length;i++){
11 int j=i,cycle=0;
12
13 while(!visited[j]){
14 visited[j]=true;
15 j=arr[j]-1;
16 cycle++;
17 }
18
19 if(cycle!=0)
20 swap+=cycle-1;
21 }
22 return swap;
23 }
24
25 public static void main(String[] args) {
26
27 Scanner scanner = new Scanner(System.in);
28 int n = scanner.nextInt();
29 int[] arr = new int[n];
30
31 for (int i = 0; i < n; i++) {
32 arr[i] = scanner.nextInt();
33 }
34
35 int res = minimumSwaps(arr);
36 System.out.println(res);
37 scanner.close();
38 }
39}
40