n,m=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
p=[0]*m
for s in S:
  k=0
  d=[0]*(m+1)
  for i in range(m):
    if T[i]==s:
      k+=p[i-1]+1
    d[i]=(p[i]+k)%(10**9+7)
  p=d
print(p[-2]+1) 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 p=[0]*m p [0]*m [0] 0 m for s in S:
  k=0
  d=[0]*(m+1)
  for i in range(m):
    if T[i]==s:
      k+=p[i-1]+1
    d[i]=(p[i]+k)%(10**9+7)
  p=d s S k=0 k 0 d=[0]*(m+1) d [0]*(m+1) [0] 0 m+1 m 1 for i in range(m):
    if T[i]==s:
      k+=p[i-1]+1
    d[i]=(p[i]+k)%(10**9+7)
   i range(m) range m if T[i]==s:
      k+=p[i-1]+1
     T[i]==s T[i] T i s k+=p[i-1]+1 k p[i-1]+1 p[i-1] p i-1 i 1 1 d[i]=(p[i]+k)%(10**9+7) d[i] d i (p[i]+k)%(10**9+7) p[i]+k p[i] p i k 10**9+7 10**9 10 9 7 p=d p d print(p[-2]+1) print p[-2]+1 p[-2] p -2 1 p=[0]*m [0]*m p d=[0]*(m+1) [0]*(m+1) d n,m=map(int,input().split()) map(int,input().split()) n k+=p[i-1]+1 p[i-1]+1 k m=map(int,input().split()) map(int,input().split()) m S=list(map(int,input().split())) list(map(int,input().split())) S T=list(map(int,input().split())) list(map(int,input().split())) T k=0 0 k p=d d p
n,m=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
p=[0]*m
for s in S:
  k=0
  d=[0]*(m+1)
  for i in range(m):
    if T[i]==s:
      k+=p[i-1]+1
    d[i]=(p[i]+k)%(10**9+7)
  p=d
print(p[-2]+1)