Problem: PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.

There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.

How many trees are there in the forest?

Input

The first line contains single integer n (1 ≤ n ≤ 104) — the number of Balls living in the forest.

The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≤ pi ≤ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id.

It's guaranteed that the sequence p corresponds to some valid forest.

Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format:

In the first line, output the integer n (1 ≤ n ≤ 104) — the number of Balls and the integer m (0 ≤ m < n) — the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows:
    
    
      
    5 3  
    1 2  
    3 4  
    4 5  
    

Output

You should output the number of trees in the forest where PolandBall lives.

Interaction

From the technical side, this problem is interactive. However, it should not affect you (except hacking) since there is no interaction.

Examples

Input

5
2 1 5 3 3

Output

2

Input

1
1


Output

1

Note

In the first sample testcase, possible forest is: 1-2 3-4-5. 

There are 2 trees overall.

In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.lang.*;


public class graph {
    static long mod=10000_00007;
   
    public static void main(String[] args) throws Exception{
        InputStreamReader ip=new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(ip);
		int n = Integer.parseInt(br.readLine());
		// StringBuilder sb = new StringBuilder();
        ArrayList<Integer> list=new ArrayList<>();

        String[] strs=(br.readLine()).trim().split(" ");

        int[] arr=new int[n];
        HashSet<Integer> hs=new HashSet<>();

        long ans=0;
        for(int i=0;i<n;i++){
            int val=Integer.parseInt(strs[i]);
            if(val==(i+1)){ans++;}
            else{hs.add(val);}
        }
        ans+=(hs.size()/2);
        System.out.println(ans);
    }
}


//     public static void main(String[] args) throws Exception{
//         InputStreamReader ip=new InputStreamReader(System.in);
//         BufferedReader br = new BufferedReader(ip);
// 		int n = Integer.parseInt(br.readLine());
// 		StringBuilder sb = new StringBuilder();
//         ArrayList<Integer> list=new ArrayList<>();

//         if(n%4==0 || n%4==2){
//             for(int i=1;i<=n;i++){
//                 if(i%4==1 || i%4==0){
//                    list.add(i); // System.out.print(i+" ");
//                 }
//             }
//         }else if(n%4==1){
//             for(int i=1;i<=(1+(n/4));i++){
//                 list.add(i);//System.out.print(i+" ");
//             }
//             for(int i=((n-(n/4))+1);i<=(n);i++){
//                 list.add(i);// System.out.print(i+" ");
//             }
//         }else if(n%4==3){
//             for(int i=1;i<=((n/4));i++){
//                 list.add(i);// System.out.print(i+" ");
//             }
//             for(int i=((n-(n/4)));i<=(n);i++){
//                 list.add(i); //System.out.print(i+" ");
//             }
//         }
//         if(n%4==0 || n%4==3){System.out.println(0);}
//         else{System.out.println(1);}
        
//         System.out.print(list.size()+" ");
//         for(int val:list){System.out.print(val+" ");}
//         System.out.println();
//     }
// }






    // public static int find(int a,int[] p){
    //     if(a!=p[a]){return p[a]=find(p[a], p);}
    //     else{return a;}
    // }
    // public static int findrank(int a,int[] p,int [] r){
    //     if(a!=p[a]){return findrank(p[a], p,r);}
    //     else{return r[a];}
    // }
    // public static void main(String[] args) throws Exception{
    //     InputStreamReader ip=new InputStreamReader(System.in);
    //     BufferedReader br = new BufferedReader(ip);
	// 	// int t = Integer.parseInt(br.readLine());
	// 	StringBuilder sb = new StringBuilder();
 
	// 	// while (t-- > 0) {
    //         String[] str = (br.readLine()).trim().split(" ");
    //         int n = Integer.parseInt(str[0]);
    //         int m=Integer.parseInt(str[1]);
    //         int[] parent=new int[n+1];
    //         int[] rank=new int[n+1];
    //         for(int i=0;i<=n;i++){parent[i]=i; rank[i]=1;}

    //         for(int i=0;i<m;i++){
    //             str = (br.readLine()).trim().split(" ");

    //             int k=Integer.parseInt(str[0]);

    //             for(int j=2;j<str.length;j++){
    //                 int a=Integer.parseInt(str[j-1]);
    //                 int b=Integer.parseInt(str[j]);
    //                 int la=find(a, parent),lb=find(b, parent);
    //                 if(la!=lb){
    //                     if(rank[la]<rank[lb]){int tmp=la; la=lb; lb=tmp;}

    //                     rank[la]+=rank[lb];
    //                     parent[lb]=la;
    //                 }
    //             }
    //         }

    //         for(int i=1;i<=n;i++){
    //             int ans=findrank(i,parent,rank);
    //             System.out.print(ans+" ");  //" r="+rank[i]+"  "
    //         }
    //         System.out.println();
    //     }
    // }

//     public static void main(String[] args) throws Exception{
//         InputStreamReader ip=new InputStreamReader(System.in);
//         BufferedReader br = new BufferedReader(ip);
// 		// int t = Integer.parseInt(br.readLine());
// 		StringBuilder sb = new StringBuilder();
 
// 		// while (t-- > 0) {
//             String[] str = (br.readLine()).trim().split(" ");
//             int n = Integer.parseInt(str[0]);
//             int m=Integer.parseInt(str[1]);
//             int k = Integer.parseInt(str[2]);
            
//             int[][] arr=new int[m][3];

//             for(int i=0;i<m;i++){
//                 str = (br.readLine()).trim().split(" ");
//                 arr[i][0]=Integer.parseInt(str[0]);
//                 arr[i][1]=Integer.parseInt(str[1]);
//                 arr[i][2]=Integer.parseInt(str[2]);
//             }
            
//             if(k==0){
//                 System.out.println(-1); 
//                 return;
//             }

//             boolean[] flr=new boolean[n+1];
//             str = (br.readLine()).trim().split(" ");
//             for(int i=0;i<k;i++){
//                 int idx=Integer.parseInt(str[i]);
//                 flr[idx]=true;
//             }

//             int ans=Integer.MAX_VALUE;

//             for(int i=0;i<m;i++){
//                 if((flr[arr[i][0]] && !flr[arr[i][1]]) || (!flr[arr[i][0]] && flr[arr[i][1]])){
//                     ans=Math.min(ans,arr[i][2]);
//                 }
//             }

//             if(ans==Integer.MAX_VALUE){
//                 System.out.println(-1);
//             }else{
//                 System.out.println(ans);
//             }
//         // }
//     }
// }



    // public static void main(String[] args) throws Exception{
    //     InputStreamReader ip=new InputStreamReader(System.in);
    //     BufferedReader br = new BufferedReader(ip);
	// 	int t = Integer.parseInt(br.readLine());
	// 	StringBuilder sb = new StringBuilder();
 
	// 	while (t-- > 0) {
    //         int n = Integer.parseInt(br.readLine());
    //         String str = (br.readLine()).trim();

    //         int cw=0,acw=0,bh=0;
    //         int ans=0;
    //         for(int i=0;i<n;i++){
    //             if(str.charAt(i)=='-'){
    //                 if(str.charAt(((i-1)+n)%n)==str.charAt(i)){
    //                     ans++;
    //                 }else{
    //                     ans+=2;
    //                 }
    //                 bh++;
    //             }else if(str.charAt(i)=='>'){
    //                 cw++;
    //             }else{
    //                 acw++;
    //             }
    //         }

    //         if(acw==n || cw==n || bh==n){
    //             System.out.println(n);
    //         }else if((acw+bh)==n || (cw+bh)==n){
    //             System.out.println(n);
    //         }else{
    //             System.out.println(ans);
    //         }
    //     }
    //     }

    // }


//      public static void main(String[] args) throws Exception{
//         InputStreamReader ip=new InputStreamReader(System.in);
//         BufferedReader br = new BufferedReader(ip);
// 		// int t = Integer.parseInt(br.readLine());
// 		StringBuilder sb = new StringBuilder();
 
// 		// while (t-- > 0) {
// 			String[] arrp = (br.readLine()).trim().split(" ");
           
//             int n = Integer.parseInt(arrp[0]);
//             int m= Integer.parseInt(arrp[1]);
            
//             String[] str = (br.readLine()).trim().split(" ");
//             int[] cost=new int[n+1];
//             for(int i=0;i<n;i++){
//                 cost[i+1]=Integer.parseInt(str[i]);
//             }
//             long ans=0;
//             for(int i=0;i<m;i++){
//                 str = (br.readLine()).trim().split(" ");

//                 int u=Integer.parseInt(str[0]);
//                 int v=Integer.parseInt(str[1]);
//                 ans+=Math.min(cost[u],cost[v]);
//             }

//             System.out.println(ans);
//         // }
//     }
// } 
    
//     public static long binexp(long a,long b){
//         long res=1;
//         while(b>0){
//             if((b&1)==1){
//                 res=res*a;  res=res%mod;
//             }
//             a=a*a; a=a%mod;
//             b>>=1;
//         }
//         return res;
//     }
//     public static void main(String[] args) throws Exception{
//         InputStreamReader ip=new InputStreamReader(System.in);
//         BufferedReader br = new BufferedReader(ip);
// 		int n = Integer.parseInt(br.readLine());
//         // StringBuilder sb = new StringBuilder();
        
//         long fact=1;
//         for(int i=1;i<=n;i++){
//             fact=((long)(fact*(long)(i)));
//             fact=fact%mod;
//         }

//         long ump=binexp(2, n-1);//(long)(Math.pow(2, n-1));
//         ump=ump%mod;
//         long ans=fact-ump;
//         if(ans<0){ans+=mod;}
//         System.out.println(ans);
//     }
// }



    // public static void main(String[] args) throws Exception{
    //     InputStreamReader ip=new InputStreamReader(System.in);
    //     BufferedReader br = new BufferedReader(ip);
	// 	// int t = Integer.parseInt(br.readLine());
	// 	StringBuilder sb = new StringBuilder();
 
	// 	// while (t-- > 0) {
	// 		String[] arrp = (br.readLine()).trim().split(" ");
           
    //         int n = Integer.parseInt(arrp[0]);
    //         int m= Integer.parseInt(arrp[1]);
            
    //         boolean[] invalid=new boolean[n+1];
    //         for(int i=0;i<m;i++){
    //             String[] pr = (br.readLine()).trim().split(" ");
    //             int val=Integer.parseInt(pr[0]);
    //             invalid[val]=true;
    //             val=Integer.parseInt(pr[1]);
    //             invalid[val]=true;
    //         }
    //         int valid=-1;
    //         for(int i=1;i<=n;i++){
    //             if(!invalid[i]){valid=i; break;}
    //         }            

    //         System.out.println(n-1);
    //         for(int i=1;i<=n;i++){
    //             if(i!=valid){System.out.println(valid+" "+i);}
    //         }
    //     }
    // }



  //Q1  
//     static int mcost=0;
//     public static void dfs(ArrayList<ArrayList<Integer>> graph,int s,boolean[] visited,int[] cost){
//         mcost=Math.min(mcost,cost[s-1]);
//         visited[s]=true;
//         for(int nbr:graph.get(s)){
//             if(visited[nbr]==false){
//                 dfs(graph,nbr,visited,cost);
//             }
//         }
//     }
//     public static void main(String[] args) throws Exception{
//         InputStreamReader ip=new InputStreamReader(System.in);
//         BufferedReader br = new BufferedReader(ip);
// 		// int t = Integer.parseInt(br.readLine());
// 		StringBuilder sb = new StringBuilder();
 
// 		// while (t-- > 0) {
// 			String[] arrp = (br.readLine()).trim().split(" ");
           
//             int n = Integer.parseInt(arrp[0]);
//             int m= Integer.parseInt(arrp[1]);
            
//             String[] strs = (br.readLine()).trim().split(" ");
//             int[] cost=new int[n];
//             ArrayList<ArrayList<Integer>> graph=new ArrayList<>();
//             graph.add(new ArrayList<>());
//             for(int i=0;i<n;i++){
//                 cost[i]=Integer.parseInt(strs[i]);
//                 graph.add(new ArrayList<>());
//             }

            
//             for(int i=0;i<m;i++){
//                 arrp = (br.readLine()).trim().split(" ");
//                 int u = Integer.parseInt(arrp[0]);
//                 int v= Integer.parseInt(arrp[1]);

//                 (graph.get(u)).add(v);
//                 (graph.get(v)).add(u);
//             }

//             //dfs
//             boolean[] visited=new boolean[n+1];
//             long ans=0;
//             for(int i=1;i<=n;i++){
//                 if(visited[i]==false){
//                     mcost=Integer.MAX_VALUE;
//                     dfs(graph,i,visited,cost);
//                     ans+=mcost;
//                 }
//             }

//             System.out.println(ans);
//         // }
//     }
// }