Title: Sugoroku

Problem:
JOI is playing a game of sugoroku alone. The sugoroku consists of N squares arranged in a straight line, each containing instructions for movement. The starting point is square 1, and the goal is square N. JOI repeats the following until reaching the goal:
- Roll a die and move forward by the number rolled, following the instructions on the new square.
- Do not follow the instructions on the square moved to.
- The game ends not only when stopping exactly at square N, but also when moving beyond square N.
Given the game board and M sets of die rolls, create a program to output the number of times the die needs to be rolled to reach the goal.

Input:
The input consists of multiple datasets. Each dataset is in the following format:
- Each dataset consists of 1+N+M lines.
- The first line of input contains two integers N and M (2 ≤ N ≤ 1000, 1 ≤ M ≤ 1000). N represents the number of squares in the sugoroku, and M represents the number of die rolls given.
- The next N lines each contain an integer between -999 and 999, representing the instruction for the i-th square of the sugoroku.
- The subsequent M lines each contain an integer between 1 and 6, representing the result of the j-th die roll.
- The second and 1+N-th lines always contain 0.
- There are no instructions to move to squares before the first square.
- In any input dataset, it is always possible to reach the goal in M or fewer die rolls.

When both N and M are 0, it indicates the end of input. The number of datasets does not exceed 5.

Output:
For each dataset, output the number of times the die needs to be rolled to reach the goal as an integer on a single line.

Input/Output Example:
(Provided input and output examples are not included here.)

# Buggy version:
for e in iter(input,'0 0'):
 N,M=map(int,e.split())
 S=[int(input())for _ in[0]*N]
 p=b=1
 for i in range(M):
  d=int(input())
  p+=d
  p+=S[~-p]
  if(N<=p)*b:print(-~i);b=0


# Fixed version:
for e in iter(input,'0 0'):
 N,M=map(int,e.split())
 S=[int(input())for _ in[0]*N]
 p=b=1
 for i in range(M):
  d=int(input())
  p+=d
  if N<=p:
   if b:print(-~i);b=0
   continue
  p+=S[~-p]
  if(N<=p)*b:print(-~i);b=0

# Buggy version:
for e in iter(input,'0 0'):
 N,M=map(int,e.split())
 k=p=1
 S=[int(input()) for _ in[0]*N]
 for d in[int(input())for _ in[0]*M]:
  p+=n if n-1<=p+i else i+S[p+i]
  if n<=p:break
  k+=1
 print(k)


# Fixed version:
for e in iter(input,'0 0'):
 N,M=map(int,e.split())
 k,p=1,0
 S=[int(input()) for _ in[0]*N]
 for d in[int(input())for _ in[0]*M]:
  p+=d if N<=p+d else d+S[p+d]
  if N<=p+1:break
  k+=1
 print(k)

# Buggy version:
def s():
 import sys
 r=sys.stdin.readline
 for e in iter(r,'0 0'):
  N,M=map(int,e.split())
  k,p=1,0
  S=[int(r()) for _ in[0]*N]
  for d in[int(r())for _ in[0]*M]:
   p+=d if N<=p+d else d+S[p+d]
   if N<=p+1:break
   k+=1
  print(k)
if'__main__'==__name__:s()


# Fixed version:
def s():
 import sys
 r=sys.stdin.readline
 for e in iter(r,'0 0\n'):
  N,M=map(int,e.split())
  k,p=1,0
  S=[int(r()) for _ in[0]*N]
  for d in[int(r())for _ in[0]*M]:
   p+=d if N<=p+d else d+S[p+d]
   if N<=p+1:break
   k+=1
  print(k)
if'__main__'==__name__:s()

# Buggy version:
import sys
r=sys.stdin.readline
for e in iter(r,'0 0\n'):
 N,M=map(int,e.split())
 k,p=1,0
 S=[int(r()) for _ in[0]*N]
 for d in[int(r())for _ in[0]*M]:
  p+=d;
  if N<=p:p+=S[p]
  if N<=p+1:break
  k+=1
 print(k)


# Fixed version:
import sys
r=sys.stdin.readline
for e in iter(r,'0 0\n'):
 N,M=map(int,e.split())
 k,p=1,0
 S=[int(r())for _ in[0]*N]
 for d in[int(r())for _ in[0]*M]:
  p+=d;
  if p<N:p+=S[p]
  if N<=p+1:break
  k+=1
 print(k)