import sys

readline = sys.stdin.readline

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

P = 10 ** 9 + 7

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

for x in range(1, N + 1):
    for y in range(1, M + 1):
        dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1]
        if S[x - 1] == T[y - 1]:
            dp[x][y] += dp[x - 1][y - 1] + 1

        dp[x][y] = dp[x][y] % P

ans = dp[N][M] + 1
print(ans % P) import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, readline().split()) N map(int, readline().split()) map int readline().split() ().split () readline split M S = list(map(int, readline().split())) S list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split T = list(map(int, readline().split())) T list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split P = 10 ** 9 + 7 P 10 ** 9 + 7 10 ** 9 10 9 7 [0] * (M + 1) for i in range(N + 1) for i in range(N + 1) i range(N + 1) range N + 1 N 1 for i in range(N + 1) [0] * (M + 1) [0] 0 M + 1 M 1 dp = [[0] * (M + 1) for i in range(N + 1)] dp [[0] * (M + 1) for i in range(N + 1)] for x in range(1, N + 1):
    for y in range(1, M + 1):
        dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1]
        if S[x - 1] == T[y - 1]:
            dp[x][y] += dp[x - 1][y - 1] + 1

        dp[x][y] = dp[x][y] % P x range(1, N + 1) range 1 N + 1 N 1 for y in range(1, M + 1):
        dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1]
        if S[x - 1] == T[y - 1]:
            dp[x][y] += dp[x - 1][y - 1] + 1

        dp[x][y] = dp[x][y] % P y range(1, M + 1) range 1 M + 1 M 1 dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1] dp[x][y] [x] dp x y dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1] dp[x][y - 1] + dp[x - 1][y] dp[x][y - 1] [x] dp x y - 1 y 1 dp[x - 1][y] [x - 1] dp x - 1 x 1 y dp[x - 1][y - 1] [x - 1] dp x - 1 x 1 y - 1 y 1 if S[x - 1] == T[y - 1]:
            dp[x][y] += dp[x - 1][y - 1] + 1

         S[x - 1] == T[y - 1] S[x - 1] S x - 1 x 1 T[y - 1] T y - 1 y 1 dp[x][y] += dp[x - 1][y - 1] + 1 dp[x][y] [x] dp x y dp[x - 1][y - 1] + 1 dp[x - 1][y - 1] [x - 1] dp x - 1 x 1 y - 1 y 1 1 dp[x][y] = dp[x][y] % P dp[x][y] [x] dp x y dp[x][y] % P dp[x][y] [x] dp x y P ans = dp[N][M] + 1 ans dp[N][M] + 1 dp[N][M] [N] dp N M 1 print(ans % P) print ans % P ans P readline = sys.stdin.readline sys.stdin.readline readline ans = dp[N][M] + 1 dp[N][M] + 1 ans M = map(int, readline().split()) map(int, readline().split()) M P = 10 ** 9 + 7 10 ** 9 + 7 P N, M = map(int, readline().split()) map(int, readline().split()) N T = list(map(int, readline().split())) list(map(int, readline().split())) T dp = [[0] * (M + 1) for i in range(N + 1)] [[0] * (M + 1) for i in range(N + 1)] dp S = list(map(int, readline().split())) list(map(int, readline().split())) S
import sys

readline = sys.stdin.readline

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

P = 10 ** 9 + 7

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

for x in range(1, N + 1):
    for y in range(1, M + 1):
        dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1]
        if S[x - 1] == T[y - 1]:
            dp[x][y] += dp[x - 1][y - 1] + 1

        dp[x][y] = dp[x][y] % P

ans = dp[N][M] + 1
print(ans % P)
