import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
s = na()
t = na()
mod = 10**9+7

dp = [[0 for i in range(m + 1)] for j in range(n + 1)]

for i in range(1, n+1):
    for j in range(1, m+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
  
print((dp[n][m]+1)%mod) import sys sys stdin = sys.stdin stdin sys.stdin sys stdin ni = lambda: int(ns()) ni lambda: int(ns()) int(ns()) int ns() ns na = lambda: list(map(int, stdin.readline().split())) na lambda: list(map(int, stdin.readline().split())) list(map(int, stdin.readline().split())) list map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split nn = lambda: list(stdin.readline().split()) nn lambda: list(stdin.readline().split()) list(stdin.readline().split()) list stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split ns = lambda: stdin.readline().rstrip() ns lambda: stdin.readline().rstrip() stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip n,m = na() n na() na m s = na() s na() na t = na() t na() na mod = 10**9+7 mod 10**9+7 10**9 10 9 7 [0 for i in range(m + 1)] for j in range(n + 1) for j in range(n + 1) j range(n + 1) range n + 1 n 1 for j in range(n + 1) [0 for i in range(m + 1)] dp = [[0 for i in range(m + 1)] for j in range(n + 1)] dp [[0 for i in range(m + 1)] for j in range(n + 1)] for i in range(1, n+1):
    for j in range(1, m+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
   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] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
   j range(1, m+1) range 1 m+1 m 1 if (s[i-1] == t[j-1]):
            dp[i][j] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
   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] = (1 + dp[i][j-1] + dp[i-1][j])%mod dp[i][j] [i] dp i j (1 + dp[i][j-1] + dp[i-1][j])%mod 1 + dp[i][j-1] + dp[i-1][j] 1 + dp[i][j-1] 1 dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j] [i-1] dp i-1 i 1 j mod dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod dp[i][j] [i] dp i j (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] dp[i][j-1] + dp[i-1][j] dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j] [i-1] dp i-1 i 1 j dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 mod print((dp[n][m]+1)%mod) print (dp[n][m]+1)%mod dp[n][m]+1 dp[n][m] [n] dp n m 1 mod stdin = sys.stdin sys.stdin stdin nn = lambda: list(stdin.readline().split()) lambda: list(stdin.readline().split()) nn m = na() na() m s = na() na() s t = na() na() t n,m = na() na() n ni = lambda: int(ns()) lambda: int(ns()) ni dp = [[0 for i in range(m + 1)] for j in range(n + 1)] [[0 for i in range(m + 1)] for j in range(n + 1)] dp mod = 10**9+7 10**9+7 mod na = lambda: list(map(int, stdin.readline().split())) lambda: list(map(int, stdin.readline().split())) na ns = lambda: stdin.readline().rstrip() lambda: stdin.readline().rstrip() ns
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
s = na()
t = na()
mod = 10**9+7

dp = [[0 for i in range(m + 1)] for j in range(n + 1)]

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