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.math.BigInteger;

public class Tester
{
	public static long mod=(long)(1e9+7);
	public static long x,y,d;
	static int p[];
	
	public static void main(String[] args) 
	{
		InputReader s=new InputReader(System.in);
        OutputStream outputStream = System.out;
        PrintWriter out=new PrintWriter(outputStream);
    
        int n= s.nextInt();
		p= new int[n+1];
		
		generateSets(n);
		
		for(int i=1;i<=n;i++)
			union(s.nextInt(),i);
		
		int count[]= new int[n+1];
		
		for(int i=1;i<=n;i++)
			count[root(i)]++;
		
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(count[i]!=0)
				ans++;
		}
		
		out.println(ans);
		
        out.close();
	}   
	
	static int firstOccurrence(int A[], int left, int right, int item) 
	{
	    int mid;
	    while (right - left > 1)
	    {
	        mid = left + (right - left) / 2;
	        if (A[mid] >= item) 
	            right = mid;
	        else
	            left = mid;
	    }
	    return right;
	}
	
	static void extendedEuclid(long A, long B)
	{
		if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	
	public static int[] generateSets(int size) 
	{    
	    for (int i = 1; i <= size; i++)
	      p[i] = i;
	    return p;
	    
	}
	
	  public static int root(int x) 
	  {
	    return x == p[x] ? x : (p[x] = root(p[x]));
	  }
	
	  public static void union(int a, int b) 
	  {
	    a = root(a);
	    b = root(b);
	    if (a != b)
	      p[a] = b;
	  }

	static boolean isPrime(long n, long k)
	{
		
		//Fermat Little Theorem
		if(n<=1 || n==4)
			return false;
		if(n<=3)
			return true;
		
		while(k-->0)
		{
			long a = 2+((long)Math.random())%(n-4);
			
			if(modulo(a,n-1,n) != 1)
				return false;
		}
		
		return true;
	}
	
	static long gcd(long a,long b)
	{
		if(b==0)
			return a;
		
		return gcd(b,a%b);
	}
	
	static long modulo(long x,long y,long p)	
	{
		 long res = 1;
		 x = x % p;  
		 
	    while (y > 0)
	    {
	        if (y%2==1)
	            res = (res*x) % p;
	 
	        y = y>>1;
	        x = (x*x) % p;  
	    }
	    return res;
	}
	
	public static void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
	
	static long exp(long a, long b)
	{
		if(b==0)
			return 1;
		if(b==1)
			return a;
		if(b==2)
			return a*a;

		if(b%2==0)
			return exp(exp(a,b/2),2);
		else
			return a*exp(exp(a,(b-1)/2),2);
	}
	
	static int findLastOccurence(int a[], int val, int lb, int ub)
	{
		int mid = (lb+ub)/2;
		
		if(mid==lb && a[mid]>val )
		{
			return -1;
		}
		
		if (a[mid] <= val && (mid == ub || a[mid + 1] > val)) 
		{
            return mid;
        }

        if (a[mid] <= val) 
        {   
            return findLastOccurence(a, val, mid + 1, ub);
        }
        else
        {
            return findLastOccurence(a, val, lb, mid);
        }
	}

	static class Pair implements Comparable<Pair>
	{
		long x,y;
		Pair(long ii, long cc)
		{
			x=ii;
			y=cc;
		}
		
		public int compareTo(Pair o) 
		{
			return Long.compare(this.x, o.x);
		}
		
		public int hashCode() {
			int hu = (int) (x ^ (x >>> 32));
			int hv = (int) (y ^ (y >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return x == other.x && y == other.y;
		}
		
		public String toString() {
			return "[x=" + x + ", y=" + y + "]";
		}
		
	}

    public static class InputReader 
    {
    	public BufferedReader reader;
    	public StringTokenizer tokenizer;
     
    	public InputReader(InputStream inputstream) 
    	{
    	      reader = new BufferedReader(new InputStreamReader(inputstream));
    	      tokenizer = null;
    	}
    	    
    	public String nextLine()
    	{
    	    String fullLine=null;
    	    while (tokenizer == null || !tokenizer.hasMoreTokens()) 
    	    {
    	        try
    	        {
    	        	fullLine=reader.readLine();
    	        } 
    	        catch (IOException e) 
    	        {
    	            throw new RuntimeException(e);
    	        }
    	        return fullLine;
    	     }
    	     return fullLine;
    	}
    		
    	public String next() 
    	{
    		while (tokenizer == null || !tokenizer.hasMoreTokens()) 
    		{
    			try
    			{
    				tokenizer = new StringTokenizer(reader.readLine());
    			}
    			catch (IOException e) 
   				{
   					throw new RuntimeException(e);
   				}
   			}
    		return tokenizer.nextToken();
    	}
    		
    	public long nextLong() 
    	{
    		return Long.parseLong(next());
    	}
    		
    	public int nextInt() 
    	{
    		return Integer.parseInt(next());
    	}
    	
    	public double nextDouble()
    	{
    		return Double.parseDouble(next());
    	}
    	
    }
 
}