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