object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val p = List.fill(n)(sc.nextInt()-1).zipWithIndex

  def solve(p: List[(Int, Int)]): Int = {
    p match {
      case (p1, idx1) :: (p2, idx2) :: rest if p1 == idx1 && p2 == idx2 => 1 + solve(rest)
      case (p1, idx1) :: rest if p1 == idx1 => 1 + solve(rest)
      case (p1, idx1) :: rest => solve(rest)
      case Nil => 0
    }
  }

  println(solve(p))
}
