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.io.*;
import java.util.*;




public class Ed93 {
	static class Reader {
	    static BufferedReader reader;
	    static StringTokenizer tokenizer;

	    /** call this method to initialize reader for InputStream */
	    static void init(InputStream input) {
	        reader = new BufferedReader(
	                     new InputStreamReader(input) );
	        tokenizer = new StringTokenizer("");
	    }

	    /** get next word */
	    static String next() throws IOException {
	        while ( ! tokenizer.hasMoreTokens() ) {
	            //TODO add check for eof if necessary
	            tokenizer = new StringTokenizer(
	                   reader.readLine() );
	        }
	        return tokenizer.nextToken();
	    }

	    static int nextInt() throws IOException {
	        return Integer.parseInt( next() );
	    }
		
	    static double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
	    static long nextLong() throws IOException {
	        return Long.parseLong( next() );
	    }
	}
	
//	int[] segmentTree;
//	public int[] createSegmentTree(int input[],int n){
//		int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); 
//		  
//        //Maximum size of segment tree 
//        int max_size = 2 * (int) Math.pow(2, x) - 1; 
//        segmentTree = new int[max_size];
//        
//        for(int i=0; i < segmentTree.length; i++){
//            segmentTree[i] = Integer.MAX_VALUE;
//        }
//        constructMinSegmentTree(segmentTree, input, 0, input.length - 1, 0);
//        return segmentTree;
//        
//    }
//	public void updateSegmentTree(int input[], int segmentTree[], int index, int delta){
//        input[index] += delta;
//        
//        updateSegmentTree(input,segmentTree, index, delta, 0, input.length - 1, 0);
//    }
//	private void constructMinSegmentTree(int segmentTree[], int input[], int low, int high,int pos){
//        if(low == high){
//        	segmentTree[pos]=input[low];
//        	return;
//        }
//        int mid = (low + high)/2;
//        constructMinSegmentTree(segmentTree, input, low, mid, 2 * pos + 1);
//        constructMinSegmentTree(segmentTree, input, mid + 1, high, 2 * pos + 2);
//        segmentTree[pos] = segmentTree[2*pos+1]|segmentTree[2*pos+2];
//    }
//	private int rangeEvenQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos){
//        if(qlow <= low && qhigh >= high){
//            return segmentTree[pos];
//        }
//        if(qlow > high || qhigh < low){
//            return 0;
//        }
//        int mid = (low+high)/2;
//        return rangeEvenQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1)|rangeEvenQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2);
//    }
//	private void updateSegmentTree(int[] input,int segmentTree[], int index, int delta, int low, int high, int pos){
//	       
//        //if index to be updated is less than low or higher than high just return.
//        if(index < low || index > high){
//            return;
//        }
//        
//        //if low and high become equal, then index will be also equal to them and update
//        //that value in segment tree at pos
//        if(low == high){
//        	segmentTree[pos]^=delta;
//        	return;
//        }
//        //otherwise keep going left and right to find index to be updated 
//        //and then update current tree position if min of left or right has
//        //changed.
//        int mid = (low + high)/2;
//        updateSegmentTree(input,segmentTree, index, delta, low, mid, 2 * pos + 1);
//        updateSegmentTree(input,segmentTree, index, delta, mid + 1, high, 2 * pos + 2);
//        segmentTree[pos] = segmentTree[2*pos+1]+ segmentTree[2*pos + 2];
//    }
//
//	static int gcd(int a, int b) 
//    { 
//        if (a == 0) 
//            return b; 
//        return gcd(b % a, a); 
//    } 
	
	
//	
	
	public static long reverse(long m) {
		
		String j=Integer.toString((int)m);
		String k="";
		for(int i=j.length()-1;i>=0;i--) {
			k+=Character.toString(j.charAt(i));
		}
		int ok=Integer.parseInt(k);
		long n=(long) ok;
		return(n);
	}
	
//	public static ArrayList<Integer> sieve() 
//    { 
//       
//		
//		ArrayList<Integer> ps =new ArrayList<Integer>();
//        boolean [] IsPrime = new boolean[(int)1e7+1]; 
//         
//        for(int i = 0; i <= 1e7; i++)
//            IsPrime[i] = true;
//         
//        for (int p = 2; p * p <= 1e7; p++) 
//        { 
//            if (IsPrime[p] == true) 
//            { 
//                for (int i = p * p; i < 1e7; i += p) 
//                    IsPrime[i] = false; 
//            } 
//        } 
//    
//        for (int p = 2; p <1e7; p++) 
//        if (IsPrime[p] == true) 
//                ps.add(p);
//        
//        return ps;
//    } 
	
	public static boolean isPrime(int n){
		
		int count=0;
		while(n%2==0) {
			count++;
			n/=2;
		}
		
		for(int i=3;i<=Math.sqrt(n);i+=2) {
			
			while(n%i==0) {
				count++;
				n/=i;
				
			}
		}
		if(n>1) {
			count++;
		}
		
		return (count==1);
	}
	
	static int nPrimes(int arr[], int n, int max) 
    { 
      
        Boolean[] prime = new Boolean[max+1]; 
        for (int i = 0; i < max + 1; i++)  
        { 
            prime[i] = true; 
        } 
  
        prime[0] = false; 
        prime[1] = false; 
        for (int p = 2; p * p <= max; p++) { 
        
           if (prime[p] == true)  
            { 
                for (int i = p * 2; i <= max; i += p) prime[i] = false; 

            } 
        } 

        int count = 0; 
        for (int i = 0; i < n; i++) {
         
            if (prime[arr[i]]) count++;
           
        } 
        return count; 
    } 
	
	public static int maxV(int[] arr) {
		int max=Integer.MIN_VALUE;
		
		for(int i=0;i<arr.length;i++) {
			max=Math.max(arr[i],max);
		}
		return max;
	}
	
	
	static class DJset{
		//int[] parent; int[] size;int n; int[] rank;
		
		public int find(int[] parent,int x) {
			if(parent[x]!=x) {
				parent[x]=find(parent,parent[x]);
			}
			return parent[x];
		}
		public void union(int a,int b,int[] parent,int[] size,int[] rank){
			int x=find(parent,a); int y=find(parent,b);
			
			if(x==y) {
				return;
			}
			if(rank[y]<rank[x]) {
				parent[y]=x;size[x]+=size[y];
			}
			else if(rank[x]<rank[y]) {
				parent[x]=y;size[y]+=size[x];
			}
			else {
				parent[x]=y;
				size[y]+=size[x];
				rank[y]+=1;
			}
			
		}
	}
	
	
	
	

	public static void main(String[] args)throws IOException{
		// TODO Auto-generated method stub
		
		
		PrintWriter pw=new PrintWriter(System.out);
		Reader.init(System.in);
		ArrayList<ArrayList<Integer>> graph=new ArrayList<ArrayList<Integer>>();
		int n=Reader.nextInt();
		
		DJset set=new DJset();
		int[] parent=new int[n];
		int[] size=new int[n];
		int[] rank=new int[n];
		for(int i=0;i<n;i++) {
			size[i]=1;
			parent[i]=i;
			rank[i]=0;
		}
		for(int i=1;i<=n;i++) {
			int x=Reader.nextInt()-1;
			
			set.union(x, i-1, parent, size, rank);
		}
		int count=0;
		for(int i=0;i<n;i++) {
			if(parent[i]==i) {
				count++;
			}
		}
		System.out.println(count);
		
		
	}

}