import bisect,collections,copy,heapq,itertools,math,numpy,string

import sys

def I(): return int(sys.stdin.readline().rstrip())

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N = I()

a = LI()

count = 0

a_dict = {}

for i,x in enumerate(a,1):

    a_dict[i] = x

for k,v in list(a_dict.items()):

    if k in [a_dict[v]]:

        count +=1

print((count//2))

import bisect,collections,copy,heapq,itertools,math,numpy,string

import sys

def I(): return int(sys.stdin.readline().rstrip())

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N = I()

a = LI()

ans = 0

for i,x in enumerate(a,1):

    if x=='*':

        continue

    if a[x-1]==i:

        ans += 1

        a[x-1] = '*'

print(ans)

import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys


def I():
    return int(sys.stdin.readline().rstrip())


def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))


N = I()
a = LI()
count = 0
a_dict = {}
for i, x in enumerate(a, 1):
    a_dict[i] = x
for k, v in list(a_dict.items()):
    if k in [a_dict[v]]:
        count += 1
print((count // 2))

import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys


def I():
    return int(sys.stdin.readline().rstrip())


def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))


N = I()
a = LI()
ans = 0
for i, x in enumerate(a, 1):
    if x == "*":
        continue
    if a[x - 1] == i:
        ans += 1
        a[x - 1] = "*"
print(ans)

-count = 0 -a_dict = {} +ans = 0 -    a_dict[i] = x -for k, v in list(a_dict.items()): -    if k in [a_dict[v]]: -        count += 1 -print((count // 2)) +    if x == "*": +        continue +    if a[x - 1] == i: +        ans += 1 +        a[x - 1] = "*" +print(ans)