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

MOD = 10 ** 9 + 7

dp = [[0 for _ in range(m)] for _ in range(n)]
sd = [[0 for _ in range(m)] for _ in range(n)]

ans = 1

if s[0] == t[0]:
    dp[0][0] = 1
    sd[0][0] = 1
    ans += 1

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

for j in range(1, m):
    if s[0] == t[j]:
        dp[0][j] = 1
        ans += 1
    sd[0][j] = dp[0][j] + sd[0][j-1]

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

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

MOD = 10 ** 9 + 7

dp = [[0 for _ in range(m)] for _ in range(n)]
sd = [[0 for _ in range(m)] for _ in range(n)]

ans = 1

if s[0] == t[0]:
    dp[0][0] = 1
    sd[0][0] = 1
    ans += 1

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

for j in range(1, m):
    if s[0] == t[j]:
        dp[0][j] = 1
        ans += 1
    sd[0][j] = dp[0][j] + sd[0][j-1]

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

print(ans)

