n,m = map(int,input().split())
s = list(input().split())
t = list(input().split())
mod = int(1e9+7)
s.insert(0,0)
t.insert(0,0)

dp = [[0 for k in range(m+1)] for i in range(n+1)] #dp[i][k]:s_i,t_k

for i in range(n+1):
    dp[i][0] = 1
for k in range(m+1):
    dp[0][k] = 1

for i in range(1,n+1):
    for k in range(1,m+1):
        if s[i] == t[k]:
            dp[i][k] = dp[i-1][k] + dp[i][k-1] - dp[i-1][k-1] + dp[i-1][k-1] 
        else:
            dp[i][k] = dp[i-1][k] + dp[i][k-1] - dp[i-1][k-1]
        
print(dp[n][m]%mod)