n = gets.chomp.to_i
p = gets.split.map(&:to_i)
p.push 0

h = Hash.new(0)

prev = (0)
count = 0
p.each_index do |i|
  if p[i] == i + 1
    if prev == i
      count += 1
    else
      h[count] += 1
      count = 1
    end
    prev = p[i]
  else
    h[count] += 1
    count = 0
  end
end
sum = 0
h.each do |k, v|
  next if k == 0

  if k == 1
    sum += v
  else
    sum += (k - 1) * v
  end
end
puts sum
