import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N, M = lr()
S = [0] + lr()
T = [0] + lr()
dp = [[0] * (M+1) for _ in range(N+1)]
dp_cum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1; dp_cum[0][0] = 1
for i in range(N+1):
    dp_cum[i][0] = 1
for j in range(M+1):
    dp_cum[0][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_cum[i-1][j-1]
        else:
            dp[i][j] = 0
        dp_cum[i][j] = (dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[i-1][j-1] + dp[i][j]) % MOD

answer = dp_cum[N][M]
print(answer)
# 02 import sys sys sr = lambda: sys.stdin.readline().rstrip() sr lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ir = lambda: int(sr()) ir lambda: int(sr()) int(sr()) int sr() sr lr = lambda: list(map(int, sr().split())) lr lambda: list(map(int, sr().split())) list(map(int, sr().split())) list map(int, sr().split()) map int sr().split() ().split () sr split MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 N, M = lr() N lr() lr M S = [0] + lr() S [0] + lr() [0] 0 lr() lr T = [0] + lr() T [0] + lr() [0] 0 lr() lr [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)] [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_cum = [[0] * (M+1) for _ in range(N+1)] dp_cum [[0] * (M+1) for _ in range(N+1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 dp_cum[0][0] = 1 dp_cum[0][0] [0] dp_cum 0 0 1 for i in range(N+1):
    dp_cum[i][0] = 1 i range(N+1) range N+1 N 1 dp_cum[i][0] = 1 dp_cum[i][0] [i] dp_cum i 0 1 for j in range(M+1):
    dp_cum[0][j] = 1 j range(M+1) range M+1 M 1 dp_cum[0][j] = 1 dp_cum[0][j] [0] dp_cum 0 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_cum[i-1][j-1]
        else:
            dp[i][j] = 0
        dp_cum[i][j] = (dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[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_cum[i-1][j-1]
        else:
            dp[i][j] = 0
        dp_cum[i][j] = (dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[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_cum[i-1][j-1]
        else:
            dp[i][j] = 0
         S[i] == T[j] S[i] S i T[j] T j dp[i][j] = dp_cum[i-1][j-1] dp[i][j] [i] dp i j dp_cum[i-1][j-1] [i-1] dp_cum i-1 i 1 j-1 j 1 dp[i][j] = 0 dp[i][j] [i] dp i j 0 dp_cum[i][j] = (dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[i-1][j-1] + dp[i][j]) % MOD dp_cum[i][j] [i] dp_cum i j (dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[i-1][j-1] + dp[i][j]) % MOD dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[i-1][j-1] + dp[i][j] dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[i-1][j-1] dp_cum[i-1][j] + dp_cum[i][j-1] dp_cum[i-1][j] [i-1] dp_cum i-1 i 1 j dp_cum[i][j-1] [i] dp_cum i j-1 j 1 dp_cum[i-1][j-1] [i-1] dp_cum i-1 i 1 j-1 j 1 dp[i][j] [i] dp i j MOD answer = dp_cum[N][M] answer dp_cum[N][M] [N] dp_cum N M print(answer) print answer ir = lambda: int(sr()) lambda: int(sr()) ir answer = dp_cum[N][M] dp_cum[N][M] answer M = lr() lr() M S = [0] + lr() [0] + lr() S N, M = lr() lr() N sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr T = [0] + lr() [0] + lr() T dp_cum = [[0] * (M+1) for _ in range(N+1)] [[0] * (M+1) for _ in range(N+1)] dp_cum 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
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N, M = lr()
S = [0] + lr()
T = [0] + lr()
dp = [[0] * (M+1) for _ in range(N+1)]
dp_cum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1; dp_cum[0][0] = 1
for i in range(N+1):
    dp_cum[i][0] = 1
for j in range(M+1):
    dp_cum[0][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_cum[i-1][j-1]
        else:
            dp[i][j] = 0
        dp_cum[i][j] = (dp_cum[i-1][j] + dp_cum[i][j-1] - dp_cum[i-1][j-1] + dp[i][j]) % MOD

answer = dp_cum[N][M]
print(answer)
# 02