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



import std.algorithm;
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[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	foreach( i; 0L .. as.length.signed - 1 )
	{
		if( as[ i ] != i + 1 && as[ i + 1 ] != i + 2 ) continue;
		as.swapAt( i, i + 1 );
		ans++;
	}
	return ans;
}
