n,m=map(x->parse(Int,x),split(readline()))
s=map(x->parse(Int,x),split(readline()))
t=map(x->parse(Int,x),split(readline()))
dp=zeros(Int,n+1,m+1)
sum=zeros(Int,n+1,m+1)
mod=10^9+7
for j=1:m+1;sum[1,j]=1;end