from numpy import*
N,M,*U= map(int,open(0).read().split())
p=ones(M+1)
for s in U[:N]:p[1:]=((p[:-1]*(s==array(U[N:]))).cumsum()+p[1:])%(10**9+7)
print(int(p[-1])) from numpy import* N,M,*U= map(int,open(0).read().split()) N map(int,open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split M *U U p=ones(M+1) p ones(M+1) ones M+1 M 1 for s in U[:N]:p[1:]=((p[:-1]*(s==array(U[N:]))).cumsum()+p[1:])%(10**9+7) s U[:N] U :N N print(int(p[-1])) print int(p[-1]) int p[-1] p -1 M,*U= map(int,open(0).read().split()) map(int,open(0).read().split()) M p=ones(M+1) ones(M+1) p N,M,*U= map(int,open(0).read().split()) map(int,open(0).read().split()) N
from numpy import*
N,M,*U= map(int,open(0).read().split())
p=ones(M+1)
for s in U[:N]:p[1:]=((p[:-1]*(s==array(U[N:]))).cumsum()+p[1:])%(10**9+7)
print(int(p[-1]))