N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

MOD = 10**9 + 7

# dp[i+1][j+1] : S_iまで，T_jまでで作ることのできる共通部分列の数
dp = [[0] * 2010 for _ in range(2010)]
dp[0][0] = 1

for i in range(N+1):
    for j in range(M+1):
        if i > 0: dp[i][j] += dp[i-1][j]
        if j > 0: dp[i][j] += dp[i][j-1]
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
        dp[i][j] = (dp[i][j] + MOD) % MOD

print(dp[N][M]) 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 MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 [0] * 2010 for _ in range(2010) for _ in range(2010) _ range(2010) range 2010 for _ in range(2010) [0] * 2010 [0] 0 2010 dp = [[0] * 2010 for _ in range(2010)] dp [[0] * 2010 for _ in range(2010)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for i in range(N+1):
    for j in range(M+1):
        if i > 0: dp[i][j] += dp[i-1][j]
        if j > 0: dp[i][j] += dp[i][j-1]
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
        dp[i][j] = (dp[i][j] + MOD) % MOD i range(N+1) range N+1 N 1 for j in range(M+1):
        if i > 0: dp[i][j] += dp[i-1][j]
        if j > 0: dp[i][j] += dp[i][j-1]
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
        dp[i][j] = (dp[i][j] + MOD) % MOD j range(M+1) range M+1 M 1 if i > 0: dp[i][j] += dp[i-1][j]
         i > 0 i 0 if j > 0: dp[i][j] += dp[i][j-1]
         j > 0 j 0 if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
         i > 0 and j > 0 i > 0 i 0 j > 0 j 0 dp[i][j] -= dp[i-1][j-1] dp[i][j] [i] dp i j dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
         S[i-1] == T[j-1] S[i-1] S i-1 i 1 T[j-1] T j-1 j 1 dp[i][j] = (dp[i][j] + MOD) % MOD dp[i][j] [i] dp i j (dp[i][j] + MOD) % MOD dp[i][j] + MOD dp[i][j] [i] dp i j MOD MOD print(dp[N][M]) print dp[N][M] [N] dp N M N, M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M dp = [[0] * 2010 for _ in range(2010)] [[0] * 2010 for _ in range(2010)] dp 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 10**9 + 7 MOD
N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

MOD = 10**9 + 7

# dp[i+1][j+1] : S_iまで，T_jまでで作ることのできる共通部分列の数
dp = [[0] * 2010 for _ in range(2010)]
dp[0][0] = 1

for i in range(N+1):
    for j in range(M+1):
        if i > 0: dp[i][j] += dp[i-1][j]
        if j > 0: dp[i][j] += dp[i][j-1]
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
        dp[i][j] = (dp[i][j] + MOD) % MOD

print(dp[N][M])