from collections import deque
from itertools import repeat

MOD = 10**9 + 7

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

if N < M:
    N,M = M,N
    S,T = T,S

dp = deque(repeat(1, M+1), M+2)


for s in S:
    dp.append(1)
    for t in T:
        if s == t:
            dp.append(dp[1]+dp[-1])
        else:
            dp.append(dp[1]-dp[0]+dp[-1])

print(dp[-1]%MOD) from collections import deque from itertools import repeat 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 = tuple(map(int,input().split())) S tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split T = tuple(map(int,input().split())) T tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split if N < M:
    N,M = M,N
    S,T = T,S N < M N M N,M = M,N N M M N S,T = T,S S T T S dp = deque(repeat(1, M+1), M+2) dp deque(repeat(1, M+1), M+2) deque repeat(1, M+1) repeat 1 M+1 M 1 M+2 M 2 for s in S:
    dp.append(1)
    for t in T:
        if s == t:
            dp.append(dp[1]+dp[-1])
        else:
            dp.append(dp[1]-dp[0]+dp[-1]) s S dp.append(1) dp.append dp append 1 for t in T:
        if s == t:
            dp.append(dp[1]+dp[-1])
        else:
            dp.append(dp[1]-dp[0]+dp[-1]) t T if s == t:
            dp.append(dp[1]+dp[-1])
        else:
            dp.append(dp[1]-dp[0]+dp[-1]) s == t s t dp.append(dp[1]+dp[-1]) dp.append dp append dp[1]+dp[-1] dp[1] dp 1 dp[-1] dp -1 dp.append(dp[1]-dp[0]+dp[-1]) dp.append dp append dp[1]-dp[0]+dp[-1] dp[1]-dp[0] dp[1] dp 1 dp[0] dp 0 dp[-1] dp -1 print(dp[-1]%MOD) print dp[-1]%MOD dp[-1] dp -1 MOD N,M = map(int,input().split()) map(int,input().split()) N S,T = T,S T S T = T,S S T N,M = M,N M N T = tuple(map(int,input().split())) tuple(map(int,input().split())) T M = map(int,input().split()) map(int,input().split()) M M = M,N N M S = tuple(map(int,input().split())) tuple(map(int,input().split())) S MOD = 10**9 + 7 10**9 + 7 MOD dp = deque(repeat(1, M+1), M+2) deque(repeat(1, M+1), M+2) dp
from collections import deque
from itertools import repeat

MOD = 10**9 + 7

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

if N < M:
    N,M = M,N
    S,T = T,S

dp = deque(repeat(1, M+1), M+2)


for s in S:
    dp.append(1)
    for t in T:
        if s == t:
            dp.append(dp[1]+dp[-1])
        else:
            dp.append(dp[1]-dp[0]+dp[-1])

print(dp[-1]%MOD)