nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007) nl = lambda: list(map(int, input().split())) nl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split sl = lambda: input().split() sl lambda: input().split() input().split() ().split () input split n = lambda: int(input()) n lambda: int(input()) int(input()) int input() input s = lambda: input() s lambda: input() input() input N, M = nl() N nl() nl M S = nl() S nl() nl T = nl() T nl() nl dp = [0] * (M+1) dp [0] * (M+1) [0] 0 M+1 M 1 for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2 i s enumerate(S) enumerate S dp2 = dp[:] dp2 dp[:] dp : for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
     j t enumerate(T) enumerate T dp2[j+1] += dp2[j] - dp[j] dp2[j+1] dp2 j+1 j 1 dp2[j] - dp[j] dp2[j] dp2 j dp[j] dp j if s == t:
            dp2[j+1] += dp[j] + 1
     s == t s t dp2[j+1] += dp[j] + 1 dp2[j+1] dp2 j+1 j 1 dp[j] + 1 dp[j] dp j 1 dp = dp2 dp dp2 print((dp[M]+1) % 1000000007) print (dp[M]+1) % 1000000007 dp[M]+1 dp[M] dp M 1 1000000007 s = lambda: input() lambda: input() s sl = lambda: input().split() lambda: input().split() sl dp = [0] * (M+1) [0] * (M+1) dp nl = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) nl T = nl() nl() T N, M = nl() nl() N M = nl() nl() M n = lambda: int(input()) lambda: int(input()) n dp = dp2 dp2 dp S = nl() nl() S dp2 = dp[:] dp[:] dp2
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)
