P27198 [AtCoder] Sugoroku
普及+
题目描述

Problem Description

JOI is playing a solo sugoroku game. This sugoroku has $N$ squares in a straight line, each with a movement instruction. The starting point is the 1st square, and the goal is the $N$th square. JOI repeats the following until reaching the goal:

Roll the dice and move from the current square by the number of spaces shown on the dice, then follow the instruction on that square. The instruction on the square just moved to is not followed.

Not only does reaching exactly the $N$th square count as a goal, but also moving beyond the $N$th square.

Given the board layout of the sugoroku and the results of $M$ dice rolls, create a program that outputs how many times the dice were rolled when the goal is reached.


Input Format

The input consists of $1 + N + M$ lines.

The first line contains two integers $N, M$ ($2 \leq N \leq 1,000$, $1 \leq M \leq 1,000$), separated by a space. $N$ represents the number of squares in the sugoroku, and $M$ represents the number of dice roll results given.

The following $N$ lines each contain one integer between $-999$ and $999$. The integer on the $(1 + i)$th line ($1 \leq i \leq N$) represents the instruction on the $i$th square of the sugoroku. Let $X$ be the written integer. When $X = 0$, it means "do nothing"; when $X > 0$, it means "move $X$ squares forward"; when $X < 0$, it means "move $|X|$ squares backward", where $|X|$ denotes the absolute value of $X$.

The following $M$ lines each contain one integer between $1$ and $6$, representing the result of the $j$th dice roll ($1 \leq j \leq M$).

Note that the numbers on the 2nd and $(1 + N)$th lines are always $0$. There are no squares with instructions to move before the 1st square. Also, for any test input, the goal can be reached within $M$ rolls of the dice.

Output Format

The output consists of one line containing a single integer representing how many times the dice were rolled when the goal is reached.


Sample Input and Output

Sample Input #1

10 5
0
0
5
6
-3
8
1
8
-4
0
1
3
5
1
5

Sample Output #1

5

Sample Input #2

10 10
0
-1
-1
4
4
-5
0
1
-6
0
1
5
2
4
6
5
5
4
1
6

Sample Output #2

6

Notes/Hints

Sample Explanation 1

2010-yo-t2-fig01.png

Sample Explanation 2

2010-yo-t2-fig02.png

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
10 5 0 0 5 6 -3 8 1 8 -4 0 1 3 5 1 5
样例输出
5