import numpy as np

N, M = map(int, input().split())
S = tuple(map(int, input().split()))
T = np.array(input().split(), np.int64)
mod = 10 ** 9 + 7

dp = np.ones(M + 1, np.int64)
for i in S:
    tmp = (T == i)
    dp[1:] = (np.cumsum(tmp * dp[:-1]) + dp[1:]) % mod

print(dp[-1]) import numpy as np numpy 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 = np.array(input().split(), np.int64) T np.array(input().split(), np.int64) np.array np array input().split() ().split () input split np.int64 np int64 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 dp = np.ones(M + 1, np.int64) dp np.ones(M + 1, np.int64) np.ones np ones M + 1 M 1 np.int64 np int64 for i in S:
    tmp = (T == i)
    dp[1:] = (np.cumsum(tmp * dp[:-1]) + dp[1:]) % mod i S tmp = (T == i) tmp T == i T i dp[1:] = (np.cumsum(tmp * dp[:-1]) + dp[1:]) % mod dp[1:] dp 1: 1 (np.cumsum(tmp * dp[:-1]) + dp[1:]) % mod np.cumsum(tmp * dp[:-1]) + dp[1:] np.cumsum(tmp * dp[:-1]) np.cumsum np cumsum tmp * dp[:-1] tmp dp[:-1] dp :-1 -1 dp[1:] dp 1: 1 mod print(dp[-1]) print dp[-1] dp -1 M = map(int, input().split()) map(int, input().split()) M dp = np.ones(M + 1, np.int64) np.ones(M + 1, np.int64) dp tmp = (T == i) T == i tmp N, M = map(int, input().split()) map(int, input().split()) N T = np.array(input().split(), np.int64) np.array(input().split(), np.int64) T S = tuple(map(int, input().split())) tuple(map(int, input().split())) S mod = 10 ** 9 + 7 10 ** 9 + 7 mod
import numpy as np

N, M = map(int, input().split())
S = tuple(map(int, input().split()))
T = np.array(input().split(), np.int64)
mod = 10 ** 9 + 7

dp = np.ones(M + 1, np.int64)
for i in S:
    tmp = (T == i)
    dp[1:] = (np.cumsum(tmp * dp[:-1]) + dp[1:]) % mod

print(dp[-1])
