import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val aArr = Array.fill(n)(sc.nextInt)

  @tailrec
  def loop(cnt: Int,num: Int):Int ={
    aArr(num - 1) match{
      case 1    => -1
      case 2    => cnt + 1
      case next => loop(cnt + 1, next)
    }
  }

  val res = loop(0, 1)

  println(res)
}