N,M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = int(1e9+7)
"""
dp[i][j] : S の i 文字目までと T の j 文字目までを考慮し、
この 2 文字 (S[i] と T[j]）をペアにするときの場合の数とすると、

dp[i][j] = (sum(dp[1:i-1][1:j-1]) + 1 if S[i] == T[j] else 0)

2-D cumsumをつかう
i,j = 0のときにきをつけて
DS[i][j] = DS[i-1][j] + DS[i][j-1] - DS[i-1][j-1] + dp[i][j]
"""

dp = [[ 0 for _ in range(M)] for _ in range(N)]
DS = [[ 0 for _ in range(M+1)] for _ in range(N+1)]
dp[0][0] = 0
#dp[0] = [ 1 ] * (M+1)
#for i in range(N+1):
#  dp[i][0] = 1

  
for i in range(N):
  for j in range(M):
    #dp[i][j] = (sum(dp[:i-1][:j-1]) + 1 if S[i-1] == T[j-1] else 0)
    if S[i] != T[j]:
      continue
    dp[i][j] += 1
    for k in range(i):
      for l in range(j):
        #if i==k and j==l:
          #continue
        dp[i][j] += dp[k][l]
    #ii = i+1 if i>0 else 0
    #jj = j+1 if j>0 else 0
    #Sumpart = DS[ii][j] + DS[i][jj] - DS[ii][jj] + dp[ii][jj]
    #dp[i][j] += (Sumpart + 1 if S[i] == T[j] else 0)
    #DS[i][j] = DS[i][j-1] + dp[i][j]
    
ans = 1 # 何も選ばない
for p in dp:
  ans += sum(p)
  ans %= mod
print(ans)
