# ABC130E

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


M = 10**9+7
n,m = map(int, input().split())
s = input().split()
t = input().split()
n = len(s)
m = len(t)
dp = [[0] * (m+2) for _ in range(n+2)] # i-1, j-1で終わる部分列の組の個数
ss = [[0] * (m+2) for _ in range(n+2)] # sum(dp[0][0]+...+ dp[i-1][j-1])

for i in range(n+2):
    dp[i][0] = 0
    ss[i][0] = 0
for j in range(m+2):
    dp[0][j] = 0
    ss[0][j] = 0

for i in range(1, n+1):
    for j in range(1, m+1):
        if s[i-1]==t[j-1]:
            dp[i][j] += (ss[i][j] + 1)
            dp[i][j] %= M
        ss[i+1][j+1] = (-ss[i][j]+ss[i+1][j]+ss[i][j+1]+dp[i][j]) % M
print(ss[n+1][m+1]+1) import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(max(1000, 10**9)) sys.setrecursionlimit sys setrecursionlimit max(1000, 10**9) max 1000 10**9 10 9 M = 10**9+7 M 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 = input().split() s input().split() ().split () input split t = input().split() t input().split() ().split () input split n = len(s) n len(s) len s m = len(t) m len(t) len t [0] * (m+2) for _ in range(n+2) for _ in range(n+2) _ range(n+2) range n+2 n 2 for _ in range(n+2) [0] * (m+2) [0] 0 m+2 m 2 dp = [[0] * (m+2) for _ in range(n+2)] dp [[0] * (m+2) for _ in range(n+2)] [0] * (m+2) for _ in range(n+2) for _ in range(n+2) _ range(n+2) range n+2 n 2 for _ in range(n+2) [0] * (m+2) [0] 0 m+2 m 2 ss = [[0] * (m+2) for _ in range(n+2)] ss [[0] * (m+2) for _ in range(n+2)] for i in range(n+2):
    dp[i][0] = 0
    ss[i][0] = 0 i range(n+2) range n+2 n 2 dp[i][0] = 0 dp[i][0] [i] dp i 0 0 ss[i][0] = 0 ss[i][0] [i] ss i 0 0 for j in range(m+2):
    dp[0][j] = 0
    ss[0][j] = 0 j range(m+2) range m+2 m 2 dp[0][j] = 0 dp[0][j] [0] dp 0 j 0 ss[0][j] = 0 ss[0][j] [0] ss 0 j 0 for i in range(1, n+1):
    for j in range(1, m+1):
        if s[i-1]==t[j-1]:
            dp[i][j] += (ss[i][j] + 1)
            dp[i][j] %= M
        ss[i+1][j+1] = (-ss[i][j]+ss[i+1][j]+ss[i][j+1]+dp[i][j]) % M i range(1, n+1) range 1 n+1 n 1 for j in range(1, m+1):
        if s[i-1]==t[j-1]:
            dp[i][j] += (ss[i][j] + 1)
            dp[i][j] %= M
        ss[i+1][j+1] = (-ss[i][j]+ss[i+1][j]+ss[i][j+1]+dp[i][j]) % M j range(1, m+1) range 1 m+1 m 1 if s[i-1]==t[j-1]:
            dp[i][j] += (ss[i][j] + 1)
            dp[i][j] %= M
         s[i-1]==t[j-1] s[i-1] s i-1 i 1 t[j-1] t j-1 j 1 dp[i][j] += (ss[i][j] + 1) dp[i][j] [i] dp i j ss[i][j] + 1 ss[i][j] [i] ss i j 1 dp[i][j] %= M dp[i][j] [i] dp i j M ss[i+1][j+1] = (-ss[i][j]+ss[i+1][j]+ss[i][j+1]+dp[i][j]) % M ss[i+1][j+1] [i+1] ss i+1 i 1 j+1 j 1 (-ss[i][j]+ss[i+1][j]+ss[i][j+1]+dp[i][j]) % M -ss[i][j]+ss[i+1][j]+ss[i][j+1]+dp[i][j] -ss[i][j]+ss[i+1][j]+ss[i][j+1] -ss[i][j]+ss[i+1][j] -ss[i][j] ss[i][j] [i] ss i j ss[i+1][j] [i+1] ss i+1 i 1 j ss[i][j+1] [i] ss i j+1 j 1 dp[i][j] [i] dp i j M print(ss[n+1][m+1]+1) print ss[n+1][m+1]+1 ss[n+1][m+1] [n+1] ss n+1 n 1 m+1 m 1 1 M = 10**9+7 10**9+7 M n = len(s) len(s) n input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input m = len(t) len(t) m m = map(int, input().split()) map(int, input().split()) m t = input().split() input().split() t s = input().split() input().split() s n,m = map(int, input().split()) map(int, input().split()) n dp = [[0] * (m+2) for _ in range(n+2)] [[0] * (m+2) for _ in range(n+2)] dp ss = [[0] * (m+2) for _ in range(n+2)] [[0] * (m+2) for _ in range(n+2)] ss
# ABC130E

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


M = 10**9+7
n,m = map(int, input().split())
s = input().split()
t = input().split()
n = len(s)
m = len(t)
dp = [[0] * (m+2) for _ in range(n+2)] # i-1, j-1で終わる部分列の組の個数
ss = [[0] * (m+2) for _ in range(n+2)] # sum(dp[0][0]+...+ dp[i-1][j-1])

for i in range(n+2):
    dp[i][0] = 0
    ss[i][0] = 0
for j in range(m+2):
    dp[0][j] = 0
    ss[0][j] = 0

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