n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

curr = a[0]
ret = 0
(n-1).times do |i|
  if curr == i + 1
    ret += 1
  else
    curr = a[i+1]
  end
end
if curr != n then
  puts ret
  exit
end
a.reverse!
curr = a[0]
ret = 0
(n-1).times do |i|
  if curr == i + 1
    ret += 1
  else
    curr = a[i+1]
  end
end
if curr != n then
  puts ret
  exit
end
