# https://atcoder.jp/contests/abc130/tasks/abc130_e
"""
タグ: LCS、二次元累積和
"""
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for _ in range(N+1)]
cum = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j] += cum[i][j] + 1
            dp[i][j]%=MOD
        cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j]
        cum[i + 1][j + 1]%=MOD
print(cum[N][M]+1) """
タグ: LCS、二次元累積和
""" import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MOD = 10**9 + 7 MOD 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 = 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 [0]*(M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0]*(M+1) [0] 0 M+1 M 1 dp = [[0]*(M+1) for _ in range(N+1)] dp [[0]*(M+1) for _ in range(N+1)] [0] * (M + 1) for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [0] * (M + 1) [0] 0 M + 1 M 1 cum = [[0] * (M + 1) for _ in range(N + 1)] cum [[0] * (M + 1) for _ in range(N + 1)] for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j] += cum[i][j] + 1
            dp[i][j]%=MOD
        cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j]
        cum[i + 1][j + 1]%=MOD i range(N) range N for j in range(M):
        if S[i]==T[j]:
            dp[i][j] += cum[i][j] + 1
            dp[i][j]%=MOD
        cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j]
        cum[i + 1][j + 1]%=MOD j range(M) range M if S[i]==T[j]:
            dp[i][j] += cum[i][j] + 1
            dp[i][j]%=MOD
         S[i]==T[j] S[i] S i T[j] T j dp[i][j] += cum[i][j] + 1 dp[i][j] [i] dp i j cum[i][j] + 1 cum[i][j] [i] cum i j 1 dp[i][j]%=MOD dp[i][j] [i] dp i j MOD cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j] cum[i + 1][j + 1] [i + 1] cum i + 1 i 1 j + 1 j 1 cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j] cum[i][j + 1] + cum[i + 1][j] - cum[i][j] cum[i][j + 1] + cum[i + 1][j] cum[i][j + 1] [i] cum i j + 1 j 1 cum[i + 1][j] [i + 1] cum i + 1 i 1 j cum[i][j] [i] cum i j dp[i][j] [i] dp i j cum[i + 1][j + 1]%=MOD cum[i + 1][j + 1] [i + 1] cum i + 1 i 1 j + 1 j 1 MOD print(cum[N][M]+1) print cum[N][M]+1 cum[N][M] [N] cum N M 1 input = sys.stdin.readline sys.stdin.readline input T = list(map(int, input().split())) list(map(int, input().split())) T dp = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] dp MOD = 10**9 + 7 10**9 + 7 MOD cum = [[0] * (M + 1) for _ in range(N + 1)] [[0] * (M + 1) for _ in range(N + 1)] cum N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M S = list(map(int, input().split())) list(map(int, input().split())) S
# https://atcoder.jp/contests/abc130/tasks/abc130_e
"""
タグ: LCS、二次元累積和
"""
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for _ in range(N+1)]
cum = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j] += cum[i][j] + 1
            dp[i][j]%=MOD
        cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j]
        cum[i + 1][j + 1]%=MOD
print(cum[N][M]+1)