J=lambda:map(int,input().split()) N,M=J() A=list(J()) b=[0]*(N+1) S=[] for s in J(): b[s]=1 S+=[s] D=S[:] for _ in range(N): E=[] for i in S: for j in D: t=A[i+j] if b[t]<1: b[t]=1 E+=[t] D=E print(sum(b))