def slove():

    import sys

    input = sys.stdin.readline

    n = int(input().rstrip('\n'))

    a = [i - 1 for i in list(map(int, input().rstrip('\n').split()))]

    cnt = 0

    for i in range(len(a)):

        if i == a[a[i]]:

            cnt += 1

    print((cnt // 2))





if __name__ == '__main__':

    slove()

import sys





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

    a = list(map(int, readline().split()))

    cnt = 0

    for i in range(n):

        if i + 1 == a[a[i]-1]:

            cnt += 1

    print((cnt // 2))





if __name__ == '__main__':

    solve()

def slove():
    import sys

    input = sys.stdin.readline
    n = int(input().rstrip("\n"))
    a = [i - 1 for i in list(map(int, input().rstrip("\n").split()))]
    cnt = 0
    for i in range(len(a)):
        if i == a[a[i]]:
            cnt += 1
    print((cnt // 2))


if __name__ == "__main__":
    slove()

import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    cnt = 0
    for i in range(n):
        if i + 1 == a[a[i] - 1]:
            cnt += 1
    print((cnt // 2))


if __name__ == "__main__":
    solve()

-def slove(): -    import sys +import sys -    input = sys.stdin.readline -    n = int(input().rstrip("\n")) -    a = [i - 1 for i in list(map(int, input().rstrip("\n").split()))] + +def solve(): +    readline = sys.stdin.buffer.readline +    mod = 10**9 + 7 +    n = int(readline()) +    a = list(map(int, readline().split())) -    for i in range(len(a)): -        if i == a[a[i]]: +    for i in range(n): +        if i + 1 == a[a[i] - 1]: -    slove() +    solve()