import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

MOD = 10 ** 9 + 7

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

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

        dp_cum[x + 1][y + 1] = (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) \
            - (dp_cum[x][y] % MOD) \
            + (dp[x + 1][y + 1] % MOD)

        dp_cum[x + 1][y + 1] %= MOD

        #print("---x,y", x, y, "----")
        #print("dp:", dp)
        #print("dp_cum", dp_cum)


ans = dp_cum[N][M] + 1
print(ans) import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines 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] * (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)] for x in range(N):
    for y in range(M):
        if S[x] == T[y]:
            dp[x + 1][y + 1] += dp_cum[x][y] + 1
            dp[x + 1][y + 1] %= MOD

        dp_cum[x + 1][y + 1] = (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) \
            - (dp_cum[x][y] % MOD) \
            + (dp[x + 1][y + 1] % MOD)

        dp_cum[x + 1][y + 1] %= MOD

        #print("---x,y", x, y, "----")
        #print("dp:", dp)
        #print("dp_cum", dp_cum) x range(N) range N for y in range(M):
        if S[x] == T[y]:
            dp[x + 1][y + 1] += dp_cum[x][y] + 1
            dp[x + 1][y + 1] %= MOD

        dp_cum[x + 1][y + 1] = (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) \
            - (dp_cum[x][y] % MOD) \
            + (dp[x + 1][y + 1] % MOD)

        dp_cum[x + 1][y + 1] %= MOD

        #print("---x,y", x, y, "----")
        #print("dp:", dp)
        #print("dp_cum", dp_cum) y range(M) range M if S[x] == T[y]:
            dp[x + 1][y + 1] += dp_cum[x][y] + 1
            dp[x + 1][y + 1] %= MOD

         S[x] == T[y] S[x] S x T[y] T y dp[x + 1][y + 1] += dp_cum[x][y] + 1 dp[x + 1][y + 1] [x + 1] dp x + 1 x 1 y + 1 y 1 dp_cum[x][y] + 1 dp_cum[x][y] [x] dp_cum x y 1 dp[x + 1][y + 1] %= MOD dp[x + 1][y + 1] [x + 1] dp x + 1 x 1 y + 1 y 1 MOD dp_cum[x + 1][y + 1] = (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) \
            - (dp_cum[x][y] % MOD) \
            + (dp[x + 1][y + 1] % MOD) dp_cum[x + 1][y + 1] [x + 1] dp_cum x + 1 x 1 y + 1 y 1 (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) \
            - (dp_cum[x][y] % MOD) \
            + (dp[x + 1][y + 1] % MOD) (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) \
            - (dp_cum[x][y] % MOD) (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) dp_cum[x+1][y] % MOD dp_cum[x+1][y] [x+1] dp_cum x+1 x 1 y MOD dp_cum[x][y + 1] % MOD dp_cum[x][y + 1] [x] dp_cum x y + 1 y 1 MOD dp_cum[x][y] % MOD dp_cum[x][y] [x] dp_cum x y MOD dp[x + 1][y + 1] % MOD dp[x + 1][y + 1] [x + 1] dp x + 1 x 1 y + 1 y 1 MOD dp_cum[x + 1][y + 1] %= MOD dp_cum[x + 1][y + 1] [x + 1] dp_cum x + 1 x 1 y + 1 y 1 MOD ans = dp_cum[N][M] + 1 ans dp_cum[N][M] + 1 dp_cum[N][M] [N] dp_cum N M 1 print(ans) print ans dp_cum = [[0] * (M+1) for _ in range(N+1)] [[0] * (M+1) for _ in range(N+1)] dp_cum M = map(int, input().split()) map(int, input().split()) M ans = dp_cum[N][M] + 1 dp_cum[N][M] + 1 ans N, M = map(int, input().split()) map(int, input().split()) N dp = [[0] * (M+1) for _ in range(N+1)] [[0] * (M+1) for _ in range(N+1)] dp read = sys.stdin.buffer.read sys.stdin.buffer.read read T = list(map(int, input().split())) list(map(int, input().split())) T readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD S = list(map(int, input().split())) list(map(int, input().split())) S
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

MOD = 10 ** 9 + 7

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

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

        dp_cum[x + 1][y + 1] = (dp_cum[x+1][y] % MOD) \
            + (dp_cum[x][y + 1] % MOD) \
            - (dp_cum[x][y] % MOD) \
            + (dp[x + 1][y + 1] % MOD)

        dp_cum[x + 1][y + 1] %= MOD

        #print("---x,y", x, y, "----")
        #print("dp:", dp)
        #print("dp_cum", dp_cum)


ans = dp_cum[N][M] + 1
print(ans)
