import numpy as np
from numba import njit

MOD = 10 ** 9 + 7

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

@njit
def solve(N, M, S, T):
    dp = np.ones((N+1, M+1), np.int64)
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
    return dp[N][M]

print(solve(N, M, S, T)) import numpy as np numpy from numba import njit MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 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 def solve(N, M, S, T):
    dp = np.ones((N+1, M+1), np.int64)
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
    return dp[N][M] solve dp = np.ones((N+1, M+1), np.int64) dp np.ones((N+1, M+1), np.int64) np.ones np ones (N+1, M+1) N+1 N 1 M+1 M 1 np.int64 np int64 for i, s in enumerate(S):
        for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
     i s enumerate(S) enumerate S for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
     j t enumerate(T) enumerate T dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] dp[i+1][j+1] [i+1] dp i+1 i 1 j+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 if s != t:
                dp[i+1][j+1] -= dp[i][j]
             s != t s t dp[i+1][j+1] -= dp[i][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i][j] [i] dp i j dp[i+1][j+1] %= MOD dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 MOD return dp[N][M] dp[N][M] [N] dp N M N N M M S S T T @njit solve njit solve print(solve(N, M, S, T)) print solve(N, M, S, T) solve N M S T S = list(map(int, input().split())) list(map(int, input().split())) S M = map(int, input().split()) map(int, input().split()) M def solve(N, M, S, T):
    dp = np.ones((N+1, M+1), np.int64)
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
    return dp[N][M] def solve(N, M, S, T):
    dp = np.ones((N+1, M+1), np.int64)
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
    return dp[N][M] solve 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()) map(int, input().split()) N
import numpy as np
from numba import njit

MOD = 10 ** 9 + 7

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

@njit
def solve(N, M, S, T):
    dp = np.ones((N+1, M+1), np.int64)
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
    return dp[N][M]

print(solve(N, M, S, T))
