unittest
{
	assert( [ "4", "2 1 4 3" ].parse.expand.solve == 2 );
	assert( [ "3", "2 3 1" ].parse.expand.solve == 0 );
	assert( [ "5", "5 5 5 5 1" ].parse.expand.solve == 1 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as[] -= 1;
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	foreach( i, j; as )
	{
		ans += ( i < j && i == as[ j ] );
	}
	return ans;
}
