read n
R=`awk '{for(i=1;i<=NF;i++)print $i}'`
cnt=0
for i in `seq $n`
do
	AA=`echo "${R}" | sed -n ${i}p`
	BB=`echo "${R}" | sed -n "${AA}"p`
	[[ $i -eq $BB ]] && cnt=$(( cnt + 1 ))
done
echo $(( cnt / 2 ))
