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