MOD = 10 ** 9 + 7
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))

dp = [0] * n
ndp = [0] * n
for tj in t:
    for i in range(n):
        ndp[i] = 0
    acc = 0
    for i, si in enumerate(s):
        if si == tj:
            ndp[i] = (dp[i] + acc + 1) % MOD
        else:
            ndp[i] = dp[i]
        acc = (acc + dp[i]) % MOD
    dp, ndp = ndp, dp
print((sum(dp) + 1) % MOD) 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 = 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 dp = [0] * n dp [0] * n [0] 0 n ndp = [0] * n ndp [0] * n [0] 0 n for tj in t:
    for i in range(n):
        ndp[i] = 0
    acc = 0
    for i, si in enumerate(s):
        if si == tj:
            ndp[i] = (dp[i] + acc + 1) % MOD
        else:
            ndp[i] = dp[i]
        acc = (acc + dp[i]) % MOD
    dp, ndp = ndp, dp tj t for i in range(n):
        ndp[i] = 0
     i range(n) range n ndp[i] = 0 ndp[i] ndp i 0 acc = 0 acc 0 for i, si in enumerate(s):
        if si == tj:
            ndp[i] = (dp[i] + acc + 1) % MOD
        else:
            ndp[i] = dp[i]
        acc = (acc + dp[i]) % MOD
     i si enumerate(s) enumerate s if si == tj:
            ndp[i] = (dp[i] + acc + 1) % MOD
        else:
            ndp[i] = dp[i]
         si == tj si tj ndp[i] = (dp[i] + acc + 1) % MOD ndp[i] ndp i (dp[i] + acc + 1) % MOD dp[i] + acc + 1 dp[i] + acc dp[i] dp i acc 1 MOD ndp[i] = dp[i] ndp[i] ndp i dp[i] dp i acc = (acc + dp[i]) % MOD acc (acc + dp[i]) % MOD acc + dp[i] acc dp[i] dp i MOD dp, ndp = ndp, dp dp ndp ndp dp print((sum(dp) + 1) % MOD) print (sum(dp) + 1) % MOD sum(dp) + 1 sum(dp) sum dp 1 MOD t = list(map(int, input().split())) list(map(int, input().split())) t m = map(int, input().split()) map(int, input().split()) m acc = (acc + dp[i]) % MOD (acc + dp[i]) % MOD acc dp, ndp = ndp, dp ndp dp ndp = [0] * n [0] * n ndp ndp = ndp, dp dp ndp dp = [0] * n [0] * n dp s = list(map(int, input().split())) list(map(int, input().split())) s MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD n, m = map(int, input().split()) map(int, input().split()) n acc = 0 0 acc
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))

dp = [0] * n
ndp = [0] * n
for tj in t:
    for i in range(n):
        ndp[i] = 0
    acc = 0
    for i, si in enumerate(s):
        if si == tj:
            ndp[i] = (dp[i] + acc + 1) % MOD
        else:
            ndp[i] = dp[i]
        acc = (acc + dp[i]) % MOD
    dp, ndp = ndp, dp
print((sum(dp) + 1) % MOD)
