mod = 10**9+7
from bisect import bisect
from collections import defaultdict
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

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

for n in range(N):
    for m in range(M):
        dp[n][m] = dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1]
        if S[n]==T[m]:
            dp[n][m] += dp[n-1][m-1]+1
        dp[n][m] %= mod

print(dp[N-1][M-1]+1) mod = 10**9+7 mod 10**9+7 10**9 10 9 7 from bisect import bisect from collections import defaultdict 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 [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 n in range(N):
    for m in range(M):
        dp[n][m] = dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1]
        if S[n]==T[m]:
            dp[n][m] += dp[n-1][m-1]+1
        dp[n][m] %= mod n range(N) range N for m in range(M):
        dp[n][m] = dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1]
        if S[n]==T[m]:
            dp[n][m] += dp[n-1][m-1]+1
        dp[n][m] %= mod m range(M) range M dp[n][m] = dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1] dp[n][m] [n] dp n m dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1] dp[n-1][m]+dp[n][m-1] dp[n-1][m] [n-1] dp n-1 n 1 m dp[n][m-1] [n] dp n m-1 m 1 dp[n-1][m-1] [n-1] dp n-1 n 1 m-1 m 1 if S[n]==T[m]:
            dp[n][m] += dp[n-1][m-1]+1
         S[n]==T[m] S[n] S n T[m] T m dp[n][m] += dp[n-1][m-1]+1 dp[n][m] [n] dp n m dp[n-1][m-1]+1 dp[n-1][m-1] [n-1] dp n-1 n 1 m-1 m 1 1 dp[n][m] %= mod dp[n][m] [n] dp n m mod print(dp[N-1][M-1]+1) print dp[N-1][M-1]+1 dp[N-1][M-1] [N-1] dp N-1 N 1 M-1 M 1 1 M = map(int,input().split()) map(int,input().split()) M dp = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] dp mod = 10**9+7 10**9+7 mod N,M = map(int,input().split()) map(int,input().split()) N S = list(map(int,input().split())) list(map(int,input().split())) S T = list(map(int,input().split())) list(map(int,input().split())) T
mod = 10**9+7
from bisect import bisect
from collections import defaultdict
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

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

for n in range(N):
    for m in range(M):
        dp[n][m] = dp[n-1][m]+dp[n][m-1]-dp[n-1][m-1]
        if S[n]==T[m]:
            dp[n][m] += dp[n-1][m-1]+1
        dp[n][m] %= mod

print(dp[N-1][M-1]+1)