n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 1000000007
dp = [1] + [1] * m
for i in range(n):
    newdp = [1] + [0] * m
    for j in range(m):
        if s[i] == t[j]:
            newdp[j + 1] = (newdp[j] + dp[j + 1]) % mod
        else:
            newdp[j + 1] = (newdp[j] + dp[j + 1] - dp[j] + mod) % mod
    dp = newdp
print(dp[-1]) 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 = 1000000007 mod 1000000007 dp = [1] + [1] * m dp [1] + [1] * m [1] 1 [1] * m [1] 1 m for i in range(n):
    newdp = [1] + [0] * m
    for j in range(m):
        if s[i] == t[j]:
            newdp[j + 1] = (newdp[j] + dp[j + 1]) % mod
        else:
            newdp[j + 1] = (newdp[j] + dp[j + 1] - dp[j] + mod) % mod
    dp = newdp i range(n) range n newdp = [1] + [0] * m newdp [1] + [0] * m [1] 1 [0] * m [0] 0 m for j in range(m):
        if s[i] == t[j]:
            newdp[j + 1] = (newdp[j] + dp[j + 1]) % mod
        else:
            newdp[j + 1] = (newdp[j] + dp[j + 1] - dp[j] + mod) % mod
     j range(m) range m if s[i] == t[j]:
            newdp[j + 1] = (newdp[j] + dp[j + 1]) % mod
        else:
            newdp[j + 1] = (newdp[j] + dp[j + 1] - dp[j] + mod) % mod
     s[i] == t[j] s[i] s i t[j] t j newdp[j + 1] = (newdp[j] + dp[j + 1]) % mod newdp[j + 1] newdp j + 1 j 1 (newdp[j] + dp[j + 1]) % mod newdp[j] + dp[j + 1] newdp[j] newdp j dp[j + 1] dp j + 1 j 1 mod newdp[j + 1] = (newdp[j] + dp[j + 1] - dp[j] + mod) % mod newdp[j + 1] newdp j + 1 j 1 (newdp[j] + dp[j + 1] - dp[j] + mod) % mod newdp[j] + dp[j + 1] - dp[j] + mod newdp[j] + dp[j + 1] - dp[j] newdp[j] + dp[j + 1] newdp[j] newdp j dp[j + 1] dp j + 1 j 1 dp[j] dp j mod mod dp = newdp dp newdp print(dp[-1]) print dp[-1] dp -1 m = map(int, input().split()) map(int, input().split()) m mod = 1000000007 1000000007 mod s = list(map(int, input().split())) list(map(int, input().split())) s newdp = [1] + [0] * m [1] + [0] * m newdp t = list(map(int, input().split())) list(map(int, input().split())) t n, m = map(int, input().split()) map(int, input().split()) n dp = [1] + [1] * m [1] + [1] * m dp dp = newdp newdp dp
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 1000000007
dp = [1] + [1] * m
for i in range(n):
    newdp = [1] + [0] * m
    for j in range(m):
        if s[i] == t[j]:
            newdp[j + 1] = (newdp[j] + dp[j + 1]) % mod
        else:
            newdp[j + 1] = (newdp[j] + dp[j + 1] - dp[j] + mod) % mod
    dp = newdp
print(dp[-1])