Problem F: 奇怪的电梯2

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:29 Solved:23

Description

      有一天小明做了一个梦,梦见了一种很奇怪的电梯。大楼的每一层楼都可以停电梯,而且第 lns="http://www.w3.org/1998/Math/MathML"> 层楼(lns="http://www.w3.org/1998/Math/MathML">1)上有一个数字 lns="http://www.w3.org/1998/Math/MathML">lns="http://www.w3.org/1998/Math/MathML">0)。电梯只有四个按钮:开,关,上,下。上下的层数等于当前楼层上的那个数字。当然,如果不能满足要求,相应的按钮就会失灵。例如: lns="http://www.w3.org/1998/Math/MathML">3,3,1,2,5 代表了 lns="http://www.w3.org/1998/Math/MathML">lns="http://www.w3.org/1998/Math/MathML">1=3lns="http://www.w3.org/1998/Math/MathML">2=3,……),从 lns="http://www.w3.org/1998/Math/MathML">1 楼开始。在 lns="http://www.w3.org/1998/Math/MathML">1 楼,按“上”可以到 lns="http://www.w3.org/1998/Math/MathML">4 楼,按“下”是不起作用的,因为没有 lns="http://www.w3.org/1998/Math/MathML">2 楼。那么,从 lns="http://www.w3.org/1998/Math/MathML"> 楼到 lns="http://www.w3.org/1998/Math/MathML"> 楼至少要按几次按钮呢?

Input

共二行。

第一行为三个用空格隔开的正整数,表示 lns="http://www.w3.org/1998/Math/MathML">,,lns="http://www.w3.org/1998/Math/MathML">1200lns="http://www.w3.org/1998/Math/MathML">1,)。

第二行为 lns="http://www.w3.org/1998/Math/MathML"> 个用空格隔开的非负整数,表示 lns="http://www.w3.org/1998/Math/MathML">

Output

一行,即最少按键次数,若无法到达,则输出 -1。

Sample Input Copy

5 1 5
3 3 1 2 5

Sample Output Copy

3