def main():

    N = int(eval(input()))

    A = [int(i)-1 for i in input().split()]



    edge = [set() for _ in range(N)]



    for i, a in enumerate(A):

        edge[i].add(a)



    ans = 0

    for i, a in enumerate(A):

        if i in edge[a]:

            ans += 1

    print((ans//2))





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    A = [int(i)-1 for i in input().split()]



    ans = 0

    for i, a in enumerate(A):

        if A[a] == i:

            ans += 1

    print((ans//2))





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    A = [int(i) - 1 for i in input().split()]
    edge = [set() for _ in range(N)]
    for i, a in enumerate(A):
        edge[i].add(a)
    ans = 0
    for i, a in enumerate(A):
        if i in edge[a]:
            ans += 1
    print((ans // 2))


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    A = [int(i) - 1 for i in input().split()]
    ans = 0
    for i, a in enumerate(A):
        if A[a] == i:
            ans += 1
    print((ans // 2))


if __name__ == "__main__":
    main()

-    edge = [set() for _ in range(N)] -    for i, a in enumerate(A): -        edge[i].add(a) -        if i in edge[a]: +        if A[a] == i: