try:
    while 1:
        N = int(input())
        l = list(map(int, input().split()))
        l = list(map(lambda x: x-1, l))
        v = [False for  _ in range(len(l))]
        c = 0
        for i in range(0,N):
            if not v[i]:
                cnt = 0
                v[i] = True
                k=l[i]
                while k!=i:
                    v[k] = True
                    cnt+=1
                    k=l[k]
                c+=cnt
        print(c)

except EOFError:
    pass



