


void main()
{
	auto io = new IO();
	auto N = io.line!size_t()[0];
	auto input = io.line!size_t();
	size_t pair = 0;
	
	foreach( i,v ; input ){
		if( i<v-1 && i==input[v-1]-1 ){
			pair++;
		}
	}
	writeln(pair);
}



import std.stdio,std.string,std.conv;
class IO
{
	string str( size_t lines = 1 )
	{
		return readln().chomp();
	}
	T[] line( T = real , string sp = " "  )( size_t lines = 1 ) 
	{
		T[] ret;
		foreach( i ; 0..lines )
			ret ~= readln().chomp().split(sp).convert!T();
		return ret;
	}
	T[][] rect( T = real , string sp = " " )( size_t lines = 1 )
	{
		T[][] ret = new T[][](lines);
		foreach( i ; 0..lines )
			ret[i] = readln().chomp().split(sp).convert!T();
		return ret;
	}
}
R[] convert( R , T )( T[] args ) pure
{
	R[] ret = new R[](args.length);
	foreach( i ; 0..args.length )
		ret[i] = args[i].to!R();
	return ret;
}

T sum( T )( in T[] args ) pure nothrow
{
	T ret = 0;
	foreach( elm ; args )
		ret += elm;
	return ret;
}

