Task
Moo Deng, the famous pygmy hippo, wants to cross a track made of tiles, numbered from to from left to right. She starts on tile and wants to reach tile .
Every tile has a jump power : standing on tile , Moo Deng can jump to any tile such that , that is, forward by at least and at most tiles. Each jump counts as one move.
Some tiles are wet. If Moo Deng lands on a wet tile , she cannot stop there: she instantly slides forward to tile , where . If is wet as well, she keeps sliding, until she reaches a dry tile. Sliding is free: it does not count as a jump. Tiles and are always dry.

One way to cross the track of the first sample case. Wet tiles are blue, jumps are solid arrows, slides are dashed. Note that the figure is partially complete.
Help Moo Deng find the minimum number of jumps she needs to reach tile , or tell her that it is impossible.
Input data
The first line contains the only integer .
The second line contains integers .
The third line contains integers : if tile is dry, otherwise tile is wet and Moo Deng slides from it to tile .
Output data
You need to write a single line with an integer: the minimum number of jumps needed to reach tile , or if tile cannot be reached.
Constraints and clarifications
- .
- for each (in particular, ).
- or for each .
- .
| # | Score | Constraints |
|---|---|---|
| 0 | 0 | Examples. |
| 1 | 10 | . |
| 2 | 15 | and there are no wet tiles ( for each ). |
| 3 | 25 | and every slide ends on a dry tile ( for each wet tile ). |
| 4 | 40 | . |
| 5 | 10 | No additional restrictions. |
Example
stdin
8
3 1 1 1 2 0 1 0
-1 -1 4 5 6 -1 -1 -1
stdout
2
Explanation
In the first sample case tiles , and are wet.
The figure shows one way to reach tile : Moo Deng jumps from tile to tile , then from tile to tile . Tile is wet, so she slides to tile ; tile is wet too, so she keeps sliding to tile . Finally she jumps from tile to tile . This route uses jumps, but it is not the best one.
From tile Moo Deng can jump to tile , or .
- If she jumps to tile , she slides to tile , which is also wet, so she keeps sliding to tile . From there one more jump takes her to tile . This route uses only jumps, which is the best possible: no single jump from tile reaches tile .
- Jumping to tile looks tempting, because it is the farthest choice, but she slides to tile , where : she is stuck forever.
- Jumping to tile is not useful: from there she can only jump to tile , reaching tile with jumps instead of .
Notice that , and do not matter, because Moo Deng never stops on a wet tile.
Example
stdin
4
2 1 0 0
-1 2 -1 -1
stdout
-1
Explanation
In the second sample case jumping to tile makes Moo Deng slide to tile , and jumping directly to tile gets her there too. Since , tile cannot be reached, and the answer is .