import collections as cc
import sys
#input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
n,m=I()
s=I()
t=I()
l=10**6
mod=10**9+7
s.append(l)
t.append(l)
pref2d=[[0]*(m+2) for i in range(n+2)]
for i in range(n+1):
    for j in range(m+1):
        i=i+1
        j=j+1
        if s[i]!=t[j]:
            pref2d=[i][j]=pref2d[i][j-1]+pref2d[i-1][j]-pref2d[i-1][j-1]
            pref2d%=mod
        else:
            pref2d=[i][j]=pref2d[i][j-1]+pref2d[i-1][j]+1
            pref2d%=mod
print((pref2d[n][m]+1)%mod)
            

            