n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [0 for i in range(m)]
mod = 10 ** 9 + 7
for si in s:
    memo = [0]
    for i, ti in enumerate(t):
        memo.append((memo[-1] + dp[i]) % mod)
    for i, ti in enumerate(t):
        if si == ti:
            dp[i] += memo[i] + 1
            dp[i] %= mod

ans = 1
for dpi in dp:
    ans += dpi
    ans %= mod
print(ans) 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 0 for i in range(m) for i in range(m) i range(m) range m for i in range(m) 0 dp = [0 for i in range(m)] dp [0 for i in range(m)] mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 for si in s:
    memo = [0]
    for i, ti in enumerate(t):
        memo.append((memo[-1] + dp[i]) % mod)
    for i, ti in enumerate(t):
        if si == ti:
            dp[i] += memo[i] + 1
            dp[i] %= mod si s memo = [0] memo [0] 0 for i, ti in enumerate(t):
        memo.append((memo[-1] + dp[i]) % mod)
     i ti enumerate(t) enumerate t memo.append((memo[-1] + dp[i]) % mod) memo.append memo append (memo[-1] + dp[i]) % mod memo[-1] + dp[i] memo[-1] memo -1 dp[i] dp i mod for i, ti in enumerate(t):
        if si == ti:
            dp[i] += memo[i] + 1
            dp[i] %= mod i ti enumerate(t) enumerate t if si == ti:
            dp[i] += memo[i] + 1
            dp[i] %= mod si == ti si ti dp[i] += memo[i] + 1 dp[i] dp i memo[i] + 1 memo[i] memo i 1 dp[i] %= mod dp[i] dp i mod ans = 1 ans 1 for dpi in dp:
    ans += dpi
    ans %= mod dpi dp ans += dpi ans dpi ans %= mod ans mod print(ans) print ans mod = 10 ** 9 + 7 10 ** 9 + 7 mod dp = [0 for i in range(m)] [0 for i in range(m)] dp m = map(int, input().split()) map(int, input().split()) m ans %= mod mod ans ans = 1 1 ans s = list(map(int, input().split())) list(map(int, input().split())) s memo = [0] [0] memo n, m = map(int, input().split()) map(int, input().split()) n ans += dpi dpi ans t = list(map(int, input().split())) list(map(int, input().split())) t
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [0 for i in range(m)]
mod = 10 ** 9 + 7
for si in s:
    memo = [0]
    for i, ti in enumerate(t):
        memo.append((memo[-1] + dp[i]) % mod)
    for i, ti in enumerate(t):
        if si == ti:
            dp[i] += memo[i] + 1
            dp[i] %= mod

ans = 1
for dpi in dp:
    ans += dpi
    ans %= mod
print(ans)
