n = int(eval(input()))

L = [int(x)-1 for x in input().split()]

# for i , j in enumerate(L):

#     print(i,j)

cnt = 0

for i in range(n):

    if L[L[i]] == i:

        cnt += 1

print((cnt//2))







import sys

input = lambda: sys.stdin.readline()

# print = lambda: sys.stdout.writeline()

def main():

    n = int(eval(input()))

    L = [int(x)-1 for x in input().split()]



    cnt = 0

    for i in range(n):

        if L[L[i]] == i:

            cnt += 1



    print((cnt//2))



if __name__ == '__main__':

    main()

n = int(eval(input()))
L = [int(x) - 1 for x in input().split()]
# for i , j in enumerate(L):
#     print(i,j)
cnt = 0
for i in range(n):
    if L[L[i]] == i:
        cnt += 1
print((cnt // 2))

import sys

input = lambda: sys.stdin.readline()
# print = lambda: sys.stdout.writeline()
def main():
    n = int(eval(input()))
    L = [int(x) - 1 for x in input().split()]
    cnt = 0
    for i in range(n):
        if L[L[i]] == i:
            cnt += 1
    print((cnt // 2))


if __name__ == "__main__":
    main()

-n = int(eval(input())) -L = [int(x) - 1 for x in input().split()] -# for i , j in enumerate(L): -#     print(i,j) -cnt = 0 -for i in range(n): -    if L[L[i]] == i: -        cnt += 1 -print((cnt // 2)) +import sys + +input = lambda: sys.stdin.readline() +# print = lambda: sys.stdout.writeline() +def main(): +    n = int(eval(input())) +    L = [int(x) - 1 for x in input().split()] +    cnt = 0 +    for i in range(n): +        if L[L[i]] == i: +            cnt += 1 +    print((cnt // 2)) + + +if __name__ == "__main__": +    main()