local function reada(n,m)m=m or 1 r={}for i=1,m do r[i]={}end for i=1,n do for j=1,m do r[j][i]=io.read"*n"end end return unpack(r)end

N=io.read"*n"
a=reada(N)

t=0
s=0
for i=1,N do
	if(a[i]~=t+1)then s=s+1
	else t=t+1 end
end

print(s~=N and s or -1)