N = gets.to_i
a=Array.new(N)
a[(0..N-1)]=gets.split.map(&:to_i)
k=0
for i in 0..N-1 do
	if a[i]==N
		if a[i-1] == N-1 
			a[i-1],a[i]= a[i],a[i-1]
			k +=1
		elsif a[i+1] == N+1 
			a[i+1],a[i]= a[i],a[i+1]
			k +=1
		elsif i>=0 && i<N
			a[i+1],a[i]= a[i],a[i+1]
			k +=1
		else
			a[i-1],a[i]= a[i],a[i-1]
			k +=1
		end
	end
end

puts k
		
		
