n,m=map(int,input().split()) #<=2*10**3
#n
s=list(map(int,input().split()))
#m
t=list(map(int,input().split()))
mod=10**9+7
ans=[0]*m

for u in s:
    h=[0]*m
    if u==t[0]:
        h[0]=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    for i in range(m):
        ans[i]=(ans[i]+h[i])%mod
print((ans[-1]+1)%mod) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m s=list(map(int,input().split())) s list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split t=list(map(int,input().split())) t list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split mod=10**9+7 mod 10**9+7 10**9 10 9 7 ans=[0]*m ans [0]*m [0] 0 m for u in s:
    h=[0]*m
    if u==t[0]:
        h[0]=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    for i in range(m):
        ans[i]=(ans[i]+h[i])%mod u s h=[0]*m h [0]*m [0] 0 m if u==t[0]:
        h[0]=1
     u==t[0] u t[0] t 0 h[0]=1 h[0] h 0 1 for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
     i range(1,m) range 1 m if t[i]==u:
            h[i]+=ans[i-1]+1
         t[i]==u t[i] t i u h[i]+=ans[i-1]+1 h[i] h i ans[i-1]+1 ans[i-1] ans i-1 i 1 1 h[i]+=h[i-1] h[i] h i h[i-1] h i-1 i 1 for i in range(m):
        ans[i]=(ans[i]+h[i])%mod i range(m) range m ans[i]=(ans[i]+h[i])%mod ans[i] ans i (ans[i]+h[i])%mod ans[i]+h[i] ans[i] ans i h[i] h i mod print((ans[-1]+1)%mod) print (ans[-1]+1)%mod ans[-1]+1 ans[-1] ans -1 1 mod s=list(map(int,input().split())) list(map(int,input().split())) s ans=[0]*m [0]*m ans h=[0]*m [0]*m h n,m=map(int,input().split()) map(int,input().split()) n t=list(map(int,input().split())) list(map(int,input().split())) t mod=10**9+7 10**9+7 mod m=map(int,input().split()) map(int,input().split()) m
n,m=map(int,input().split()) #<=2*10**3
#n
s=list(map(int,input().split()))
#m
t=list(map(int,input().split()))
mod=10**9+7
ans=[0]*m

for u in s:
    h=[0]*m
    if u==t[0]:
        h[0]=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    for i in range(m):
        ans[i]=(ans[i]+h[i])%mod
print((ans[-1]+1)%mod)