n = int(input()) p = list(map(int, input().split())) visited = [False] * n total = 0 for i in range(n): if not visited[i]: if p[i] == i + 1: visited[i] = True continue cycle_length = 0 current = i while not visited[current]: visited[current] = True cycle_length += 1 current = p[current] - 1 total += (cycle_length - 1) print(total)