import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M = MI()
S = [0] + LI()
T = [0] + LI()
mod = 10**9+7

dp = [[0]*(M+1) for _ in range(N+1)]
# dp[i][j] = S[:i+1] と T[:j+1] に対する答え

for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i] == T[j]:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]+1
        else:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
        dp[i][j] %= mod

print(dp[N][M]+1)  # 空列を追加 import sys sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI N,M = MI() N MI() MI M S = [0] + LI() S [0] + LI() [0] 0 LI() LI T = [0] + LI() T [0] + LI() [0] 0 LI() LI mod = 10**9+7 mod 10**9+7 10**9 10 9 7 [0]*(M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0]*(M+1) [0] 0 M+1 M 1 dp = [[0]*(M+1) for _ in range(N+1)] dp [[0]*(M+1) for _ in range(N+1)] for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i] == T[j]:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]+1
        else:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
        dp[i][j] %= mod i range(1,N+1) range 1 N+1 N 1 for j in range(1,M+1):
        if S[i] == T[j]:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]+1
        else:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
        dp[i][j] %= mod j range(1,M+1) range 1 M+1 M 1 if S[i] == T[j]:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]+1
        else:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
         S[i] == T[j] S[i] S i T[j] T j dp[i][j] = dp[i-1][j]+dp[i][j-1]+1 dp[i][j] [i] dp i j dp[i-1][j]+dp[i][j-1]+1 dp[i-1][j]+dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 1 dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1] dp[i][j] [i] dp i j dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1] dp[i-1][j]+dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 dp[i][j] %= mod dp[i][j] [i] dp i j mod print(dp[N][M]+1) print dp[N][M]+1 dp[N][M] [N] dp N M 1 def MI(): return map(int,sys.stdin.readline().rstrip().split()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI M = MI() MI() M T = [0] + LI() [0] + LI() T def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI S = [0] + LI() [0] + LI() S mod = 10**9+7 10**9+7 mod dp = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] dp N,M = MI() MI() N
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M = MI()
S = [0] + LI()
T = [0] + LI()
mod = 10**9+7

dp = [[0]*(M+1) for _ in range(N+1)]
# dp[i][j] = S[:i+1] と T[:j+1] に対する答え

for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i] == T[j]:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]+1
        else:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
        dp[i][j] %= mod

print(dp[N][M]+1)  # 空列を追加
