import numpy as np

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

neq = (S[:, None] != T[None, :])
dp = np.ones(M + 1, dtype=np.int64)
for i in range(N):
    new_dp = dp.copy()
    new_dp[1:] -= dp[:-1] * neq[i]
    np.cumsum(new_dp, out=new_dp)
    dp = new_dp % MOD
print(dp[M]) 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 = np.array(list(map(int, input().split()))) S np.array(list(map(int, input().split()))) np.array np array list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = np.array(list(map(int, input().split()))) T np.array(list(map(int, input().split()))) np.array np array list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 neq = (S[:, None] != T[None, :]) neq S[:, None] != T[None, :] S[:, None] S : T[None, :] T None dp = np.ones(M + 1, dtype=np.int64) dp np.ones(M + 1, dtype=np.int64) np.ones np ones M + 1 M 1 dtype=np.int64 dtype np.int64 np int64 for i in range(N):
    new_dp = dp.copy()
    new_dp[1:] -= dp[:-1] * neq[i]
    np.cumsum(new_dp, out=new_dp)
    dp = new_dp % MOD i range(N) range N new_dp = dp.copy() new_dp dp.copy() dp.copy dp copy new_dp[1:] -= dp[:-1] * neq[i] new_dp[1:] new_dp 1: 1 dp[:-1] * neq[i] dp[:-1] dp :-1 -1 neq[i] neq i np.cumsum(new_dp, out=new_dp) np.cumsum np cumsum new_dp out=new_dp out new_dp dp = new_dp % MOD dp new_dp % MOD new_dp MOD print(dp[M]) print dp[M] dp M dp = new_dp % MOD new_dp % MOD dp S = np.array(list(map(int, input().split()))) np.array(list(map(int, input().split()))) S MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD dp = np.ones(M + 1, dtype=np.int64) np.ones(M + 1, dtype=np.int64) dp N, M = map(int, input().split()) map(int, input().split()) N T = np.array(list(map(int, input().split()))) np.array(list(map(int, input().split()))) T M = map(int, input().split()) map(int, input().split()) M neq = (S[:, None] != T[None, :]) S[:, None] != T[None, :] neq new_dp = dp.copy() dp.copy() new_dp
import numpy as np

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

neq = (S[:, None] != T[None, :])
dp = np.ones(M + 1, dtype=np.int64)
for i in range(N):
    new_dp = dp.copy()
    new_dp[1:] -= dp[:-1] * neq[i]
    np.cumsum(new_dp, out=new_dp)
    dp = new_dp % MOD
print(dp[M])
