object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val list = List.fill(n)(sc.nextInt)
  val ans = list.
    zipWithIndex.
    map { case (t1, t2) =>
      if (t1 > t2 + 1)
        (t2 + 1, t1)
      else
        (t1, t2 + 1)
    }.
    groupBy(identity).
    values.
    count(p => p.size == 2)
  println(ans)
}