import sys
input = sys.stdin.readline

n,m = map(int,input().split())
s = tuple(map(int,input().split()))
t = tuple(map(int,input().split()))

mod = 10**9+7

dp = [[0]*m for _ in [0]*n]
a = [[0]*m for _ in [0]*n]

for i in range(n):
    a[i][0] = a[i-1][0]
    if t[0] == s[i]:
        dp[i][0] = 1
        a[i][0] += 1

for i in range(m):
    a[0][i] = a[0][i-1]
    if s[0] == t[i]:
        dp[0][i] = 1
        a[0][i] += 1

for i in range(1,n):
    for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = (a[i-1][j-1]+1)%mod
        a[i][j] = (a[i-1][j] + a[i][j-1] - a[i-1][j-1] + dp[i][j]) %mod

res = 1
for i in range(n):
    res = (res + sum(dp[i]))%mod
print(res%mod) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 = tuple(map(int,input().split())) t tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split mod = 10**9+7 mod 10**9+7 10**9 10 9 7 [0]*m for _ in [0]*n for _ in [0]*n _ [0]*n [0] 0 n for _ in [0]*n [0]*m [0] 0 m dp = [[0]*m for _ in [0]*n] dp [[0]*m for _ in [0]*n] [0]*m for _ in [0]*n for _ in [0]*n _ [0]*n [0] 0 n for _ in [0]*n [0]*m [0] 0 m a = [[0]*m for _ in [0]*n] a [[0]*m for _ in [0]*n] for i in range(n):
    a[i][0] = a[i-1][0]
    if t[0] == s[i]:
        dp[i][0] = 1
        a[i][0] += 1 i range(n) range n a[i][0] = a[i-1][0] a[i][0] [i] a i 0 a[i-1][0] [i-1] a i-1 i 1 0 if t[0] == s[i]:
        dp[i][0] = 1
        a[i][0] += 1 t[0] == s[i] t[0] t 0 s[i] s i dp[i][0] = 1 dp[i][0] [i] dp i 0 1 a[i][0] += 1 a[i][0] [i] a i 0 1 for i in range(m):
    a[0][i] = a[0][i-1]
    if s[0] == t[i]:
        dp[0][i] = 1
        a[0][i] += 1 i range(m) range m a[0][i] = a[0][i-1] a[0][i] [0] a 0 i a[0][i-1] [0] a 0 i-1 i 1 if s[0] == t[i]:
        dp[0][i] = 1
        a[0][i] += 1 s[0] == t[i] s[0] s 0 t[i] t i dp[0][i] = 1 dp[0][i] [0] dp 0 i 1 a[0][i] += 1 a[0][i] [0] a 0 i 1 for i in range(1,n):
    for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = (a[i-1][j-1]+1)%mod
        a[i][j] = (a[i-1][j] + a[i][j-1] - a[i-1][j-1] + dp[i][j]) %mod i range(1,n) range 1 n for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = (a[i-1][j-1]+1)%mod
        a[i][j] = (a[i-1][j] + a[i][j-1] - a[i-1][j-1] + dp[i][j]) %mod j range(1,m) range 1 m if s[i] == t[j]:
            dp[i][j] = (a[i-1][j-1]+1)%mod
         s[i] == t[j] s[i] s i t[j] t j dp[i][j] = (a[i-1][j-1]+1)%mod dp[i][j] [i] dp i j (a[i-1][j-1]+1)%mod a[i-1][j-1]+1 a[i-1][j-1] [i-1] a i-1 i 1 j-1 j 1 1 mod a[i][j] = (a[i-1][j] + a[i][j-1] - a[i-1][j-1] + dp[i][j]) %mod a[i][j] [i] a i j (a[i-1][j] + a[i][j-1] - a[i-1][j-1] + dp[i][j]) %mod a[i-1][j] + a[i][j-1] - a[i-1][j-1] + dp[i][j] a[i-1][j] + a[i][j-1] - a[i-1][j-1] a[i-1][j] + a[i][j-1] a[i-1][j] [i-1] a i-1 i 1 j a[i][j-1] [i] a i j-1 j 1 a[i-1][j-1] [i-1] a i-1 i 1 j-1 j 1 dp[i][j] [i] dp i j mod res = 1 res 1 for i in range(n):
    res = (res + sum(dp[i]))%mod i range(n) range n res = (res + sum(dp[i]))%mod res (res + sum(dp[i]))%mod res + sum(dp[i]) res sum(dp[i]) sum dp[i] dp i mod print(res%mod) print res%mod res mod dp = [[0]*m for _ in [0]*n] [[0]*m for _ in [0]*n] dp mod = 10**9+7 10**9+7 mod s = tuple(map(int,input().split())) tuple(map(int,input().split())) s a = [[0]*m for _ in [0]*n] [[0]*m for _ in [0]*n] a input = sys.stdin.readline sys.stdin.readline input t = tuple(map(int,input().split())) tuple(map(int,input().split())) t res = (res + sum(dp[i]))%mod (res + sum(dp[i]))%mod res m = map(int,input().split()) map(int,input().split()) m res = 1 1 res n,m = map(int,input().split()) map(int,input().split()) n
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
s = tuple(map(int,input().split()))
t = tuple(map(int,input().split()))

mod = 10**9+7

dp = [[0]*m for _ in [0]*n]
a = [[0]*m for _ in [0]*n]

for i in range(n):
    a[i][0] = a[i-1][0]
    if t[0] == s[i]:
        dp[i][0] = 1
        a[i][0] += 1

for i in range(m):
    a[0][i] = a[0][i-1]
    if s[0] == t[i]:
        dp[0][i] = 1
        a[0][i] += 1

for i in range(1,n):
    for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = (a[i-1][j-1]+1)%mod
        a[i][j] = (a[i-1][j] + a[i][j-1] - a[i-1][j-1] + dp[i][j]) %mod

res = 1
for i in range(n):
    res = (res + sum(dp[i]))%mod
print(res%mod)