# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits

def main():

    N = int(eval(input()))

    A = tuple(map(int, input().split()))

    ans, cand = 0, set()

    for i, j in enumerate(A, 1):

        i, j = min(i, j), max(i, j)

        if (i, j) in cand:

            ans += 1

        else:

            cand |= {(i, j)}

    print(ans)





if __name__ == "__main__":

    main()
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits

# exhaustive search

def main():

    N = int(eval(input()))

    A = [0] + list(map(int, input().split()))

    ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2

    print(ans)





if __name__ == "__main__":

    main()
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits
def main():
    N = int(eval(input()))
    A = tuple(map(int, input().split()))
    ans, cand = 0, set()
    for i, j in enumerate(A, 1):
        i, j = min(i, j), max(i, j)
        if (i, j) in cand:
            ans += 1
        else:
            cand |= {(i, j)}
    print(ans)


if __name__ == "__main__":
    main()

# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits
# exhaustive search
def main():
    N = int(eval(input()))
    A = [0] + list(map(int, input().split()))
    ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2
    print(ans)


if __name__ == "__main__":
    main()

+# exhaustive search -    A = tuple(map(int, input().split())) -    ans, cand = 0, set() -    for i, j in enumerate(A, 1): -        i, j = min(i, j), max(i, j) -        if (i, j) in cand: -            ans += 1 -        else: -            cand |= {(i, j)} +    A = [0] + list(map(int, input().split())) +    ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2