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



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 )
{
	if( as.find( 1 ).empty ) return -1;
	
	auto ans = 0L;
	auto j = 1L;
	foreach( i, a; as )
	{
		if( a == j ) j++;
		else         ans++;
	}
	return ans;
}
