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.
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class SuffixArray {
    private static InputStream stream;
    private static byte[] buf = new byte[1024];
    private static int curChar;
    private static int numChars;
    private static SpaceCharFilter filter;
    private static PrintWriter pw;
    private static long max = Long.MIN_VALUE;
    private static int mod = 1000000000+7;
    private static long mod1=(long) Math.pow(2, 32);
    
    private static void soln() {
    	int n=nextInt();
    	LinkedList<Integer>[] l=new LinkedList[n+1];
    	for(int i=0;i<=n;i++)
    		l[i]=new LinkedList();
    	for(int i=1;i<=n;i++){
    		int x=nextInt();
    		l[i].add(x);
    		l[x].add(i);
    	}
    	boolean[] visited=new boolean[n+1];
    	int cnt=0;
    	for(int i=1;i<=n;i++){
    		if(!visited[i]){
    			cnt++;
    			DFS(i,-1,visited,l);
    		}
    	}
    	pw.println(cnt);
    }
    private static long BFS(LinkedList<Integer>[] l,int n){
    	boolean[] visited=new boolean[n];
    	LinkedList<Box> map=new LinkedList();
    	//HashMap<Long,Long> map1=new HashMap();
    	long ans=0;
    	for(int cur=0;cur<n;cur++){
    		if(!visited[cur]){
    			PriorityQueue<Integer> q=new PriorityQueue();
    			long val1=0;
    	    	long val2=0;
		    	visited[cur]=true;
		    	q.add(cur);
		    	while(!q.isEmpty()){
		    		int x=q.poll();
		    		Iterator<Integer> i=l[x].listIterator();
		    		visited[x]=true;
		    		while(i.hasNext()){
		    			int y=i.next();
		    			val2++;
		    			if(!visited[y]){
		    				val1++;
		    				ans+=val1*(val1+1);
		    				visited[y]=true;
		    				q.add(y);
		    			}
		    		}
		    	}
		    	val2/=2;
		    	val2-=val1;
		    	map.add(0,new Box(val1,val2));
		    	//System.out.println(cur+" "+val1);
    		}
    	}
    	Collections.sort(map);
    	//System.out.println(map.size());
    	long ans1=0;
    	long cnt=0;
    	Iterator<Box> i =map.descendingIterator();
    	while(i.hasNext()){
    		Box val1=i.next();
    		//System.out.println(val1.i1+" "+val1.i2);
    		ans+=ans1*val1.i1;
    		ans1+=val1.i1*(val1.i1+1);
    		cnt+=val1.i2;
    	}
    	ans+=ans1*cnt;
    	return ans;
    }
    private static class Box implements Comparable<Box>{
    	long i1;
    	long i2;
    	public Box(long x1,long x2){
    		i1=x1;
    		i2=x2;
    	}
		@Override
		public int compareTo(Box arg0) {
			if(this.i1>arg0.i1)
				return 1;
			else if(this.i1==arg0.i1)
				return 0;
			else
				return -1;
			//return this.i-arg0.i;
		}
    }
    private static void DFS(int cur,int prev,boolean[] visited,LinkedList<Integer>[] l){
    	Iterator<Integer> i=l[cur].listIterator();
    	visited[cur]=true;
    	while(i.hasNext()){
    		int x=i.next();
    		if(!visited[x] && x!=prev){
    			DFS(x,cur,visited,l);
    		}
    	}
    }
	private static long mat_power(long n){
		long[][] matrix={{1,1},{1,0}};
		long[][] temp={{1,0},{0,1}};
		while(n!=0){
			if(n%2!=0){
				matrix_multiplication(temp,matrix);
			}
			matrix_multiplication(matrix,matrix);
			n>>=1;
		}
		return temp[0][1];
	}
	private static void matrix_multiplication(long[][] a,long[][] b){
		long[][] result=new long[2][2];
		for(int i = 0 ; i < 2 ; i ++)
	        for(int j = 0 ; j < 2 ; j++)
	            for(int k = 0 ; k < 2 ; k++)
	                result[i][j] = (result[i][j] + a[i][k]*b[k][j]) % mod;
	    for(int i = 0 ; i < 2 ; i++)
	        for(int j = 0 ; j < 2 ; j++)
	            a[i][j] = result[i][j];
	}
    private static long power(long x,long y,long p){
    	long res = 1; 
        x = x % p;
        while (y > 0){
            if ((y & 1)!=0)
                res = (long)((long)res*(long)x) % p;
            y = y>>1; // y = y/2
            x =(long) ((long)x*(long)x) % p;
        }
        return res;
    }
    public static class Suffix implements Comparable<Suffix>{
        int index;
        int[] rank=new int[2];
        @Override
        public int compareTo(Suffix arg0){
            return (this.rank[0]==arg0.rank[0])?(this.rank[1]<arg0.rank[1]?-1:1):(this.rank[0]<arg0.rank[0]?-1:1);
        }   
    }
    private static int[] buildSuffix(String s,int n){
        Suffix[] arr=new Suffix[n];
        for(int i=0;i<n;i++)
            arr[i]=new Suffix();
        for(int i=0;i<n;i++){
            arr[i].index=i;
            arr[i].rank[0]=s.charAt(i)-'a';
            arr[i].rank[1]=((i+1)<n)?(s.charAt(i+1)-'a'):-1;
        }
        Arrays.sort(arr);
        //for(int i=0;i<n;i++)
            //System.out.print(arr[i].index);
        int[] ind=new int[n];
        for(int k=4;k<2*n;k=k*2){
            int rank=0;
            int p_rank=arr[0].rank[0];
            arr[0].rank[0]=rank;
            ind[arr[0].index]=0;
            for(int i=1;i<n;i++){
                if (arr[i].rank[0] == p_rank && arr[i].rank[1] == arr[i-1].rank[1]) {
                    p_rank = arr[i].rank[0];
                    arr[i].rank[0] = rank;
                }
                else{
                    p_rank = arr[i].rank[0];
                    arr[i].rank[0] = ++rank;
                }
                ind[arr[i].index] = i;
            }
            for(int i=0;i<n;i++){
                int n_index=arr[i].index + k/2;
                arr[i].rank[1]=(n_index<n)?arr[ind[n_index]].rank[0] : -1;
            }
            Arrays.sort(arr);
        }
        int[] suffixArr=new int[n];
        for(int i=0;i<n;i++)
            suffixArr[i]=arr[i].index;
        return suffixArr;
    }
    private static long pow(long a, long b, long c) {
        if (b == 0)
            return 1;
        long p = pow(a, b / 2, c);
        p = (p * p) % c;
        return (b % 2 == 0) ? p : (a * p) % c;
    }

    private static class Pair implements Comparable<Pair> {
        int x;
        String y;

        public Pair(int a, String b) {
            x = a;
            y = b;
        }

        @Override
        public int compareTo(Pair arg0) {
            return this.x-arg0.x;
        }
    }

    private static long gcd(long x, long y) {
        if (y == 0)
            return x;
        return gcd(y, x % y);
    }

    private static long max(long a, long b) {
        if (a > b)
            return a;
        return b;
    }

    private static long min(long a, long b) {
        if (a < b)
            return a;
        return b;
    }

    public static void main(String[] args) throws Exception {
    	new Thread(null, new Runnable() {
			public void run() {
				try {
					InputReader(System.in);
			        pw = new PrintWriter(System.out);
			        soln();
			        pw.close();
					soln();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
    }

    public static void InputReader(InputStream stream1) {
        stream = stream1;
    }

    private static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private static boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

    private static int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    private static int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static long nextLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private static String nextToken() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private static String nextLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    private static int[] nextIntArray(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }
        return arr;
    }

    private static long[] nextLongArray(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = nextLong();
        }
        return arr;
    }

    private static void pArray(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        return;
    }

    private static void pArray(long[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        return;
    }

    private static boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    private interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}