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:
/**
 * @author teenGraph
 * @Date 27 May 2021 10:03:27PM 
 *  What is Life
 * 
 * 
 * 
 * */

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.List;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.Comparator;
import java.util.stream.IntStream;
import java.util.ArrayDeque;
import java.util.Set;
import java.util.HashSet;
import java.util.PriorityQueue;
import static java.lang.Math.max;
import static java.lang.Math.min;
 
public class Main {
    private static PrintWriter out = new PrintWriter(System.out);
    private static List<Integer> graph[];
    public static void main(String [] str)
    {
        int n = fs.nextInt();
        graph = new ArrayList[n+1];
        for(int i=0;i<n;i++)
        {
            int a = fs.nextInt();
            if(graph[i+1]==null) graph[i+1] = new ArrayList<>();
            if(graph[a]==null) graph[a] = new ArrayList<>();
            graph[i+1].add(a);
            graph[a].add(i+1);
        }
        int count =0;
        vis = new boolean [n+1];
        for(int i=1;i<=n;i++)
        {
            if(!vis[i])
            {
                dfs(i);
                // System.out.println(i);
                count++;
            }
        }

        out.println(count);
        out.close();





    }
    private static boolean vis[];
    private static void dfs(int start)
    {
        vis[start] = true;
        for(int i: graph[start])
        {
            if(!vis[i])
            {
                dfs(i);
            }
        }
    }
    // 
    /**
     * [returns the gcd of the two numbers]
     * @param  a [Integer]
     * @param  b [Integer]
     * @return   [gcd of the two numbers]
     * 
     */
    
    private static int gcd(int a,int b)
    {
        if(b==0) return a;
        return gcd(b,a%b);
    }

     interface Input {
        public String next();
        public String nextLine();
        public int nextInt();
        public long nextLong();
        public double nextDouble();
    }
    static class StdIn implements Input {
        final private int BUFFER_SIZE = 1 << 16;
        final private int STRING_SIZE = 1 << 11;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public StdIn() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
        
        public StdIn(String fi1ame) {
            try{
                din = new DataInputStream(new FileInputStream(fi1ame));
            } catch(Exception e) {
                throw new RuntimeException();
            }
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
        
        public String next() {
            byte[] buf = new byte[STRING_SIZE]; // string 1gth
            int cnt = 0, c;
            while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
            while (c != -1)
            {
                if (c == ' ' || c == '\n'||c=='\r')
                    break;
                buf[cnt++] = (byte) c;
                c=read();
            }
            return new String(buf, 0, cnt);
        }
 
        public String nextLine() {
            byte[] buf = new byte[STRING_SIZE]; // line 1gth
            int cnt = 0, c;
            while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
            while (c != -1)
            {
                if (c == '\n'||c=='\r')
                    break;
                buf[cnt++] = (byte) c;
                c = read();
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
        
        public int[] readIntArray(int n) {
            int[] ar = new int[n];
            for(int i=0; i<n; ++i)
                ar[i]=nextInt();
            return ar;
        }
 
        public long nextLong() {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() {
            try{
                if (bufferPointer == bytesRead)
                    fillBuffer();
                return buffer[bufferPointer++];
            } catch(IOException e) {
                throw new RuntimeException();
            }
        }
 
        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }
    private static StdIn fs = new StdIn();
 
   
}