object Main
  extends App {
  val _ = readInt
  val ans = readLine.split(" ").map(_.toInt)
    .zipWithIndex
    .map { case (n, i) => (n, n == i + 1) }
    .map(next)
    .toSeq
    .sequence
    .run(Acc(0, false))
    ._1.count
  println(ans)

  case class Acc(count: Int, isBeforeTrue: Boolean)
  def next(now: (Int, Boolean)): State[Acc, Unit] = State((acc: Acc) => (acc, now) match {
    case (Acc(count, false), (_, true))  => (Acc(count + 1, true), ())
    case (Acc(count, true), (_, true))   => (Acc(count, false), ())
    case (Acc(count, true), (_, false))  => (Acc(count, false), ())
    case (Acc(count, false), (_, false)) => (Acc(count, false), ())
  })

  case class State[S, A](run: S => (S, A)) {
    def map[B](f: A => B): State[S, B] = flatMap[B](a => State.unit(f(a)))

    def flatMap[B](f: A => State[S, B]): State[S, B] = State(s => {
      val (s1, a) = run(s)
      f(a).run(s1)
    })
  }

  object State {
    def unit[S, A](a: A): State[S, A] = State(s => (s, a))
  }

  implicit class SeqOps[S, A](seq: Seq[State[S, A]]) {
    def sequence: State[S, Seq[A]] = seq.foldLeft[State[S, Seq[A]]](State.unit(Nil)) { case (acc, s) => acc.flatMap(a => s.map(b => b +: a)) }
  }

}