from collections import defaultdict

N, M = map(int, input().split())
S = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
mod = 10 ** 9 + 7
sum_dp = []
for i in range(N+1):
    sum_dp.append([0] * (M+1))

for i in range(1, N+1):
    for j in range(1, M+1):
        temp = 0
        if(S[i] == T[j]):
            temp = sum_dp[i-1][j-1] + 1
        sum_dp[i][j] = (sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + temp)
        sum_dp[i][j] %= mod
        
print(sum_dp[N][M] + 1) from collections import defaultdict N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = [0] + list(map(int, input().split())) S [0] + list(map(int, input().split())) [0] 0 list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = [0] + list(map(int, input().split())) T [0] + list(map(int, input().split())) [0] 0 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 sum_dp = [] sum_dp [] for i in range(N+1):
    sum_dp.append([0] * (M+1)) i range(N+1) range N+1 N 1 sum_dp.append([0] * (M+1)) sum_dp.append sum_dp append [0] * (M+1) [0] 0 M+1 M 1 for i in range(1, N+1):
    for j in range(1, M+1):
        temp = 0
        if(S[i] == T[j]):
            temp = sum_dp[i-1][j-1] + 1
        sum_dp[i][j] = (sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + temp)
        sum_dp[i][j] %= mod
         i range(1, N+1) range 1 N+1 N 1 for j in range(1, M+1):
        temp = 0
        if(S[i] == T[j]):
            temp = sum_dp[i-1][j-1] + 1
        sum_dp[i][j] = (sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + temp)
        sum_dp[i][j] %= mod
         j range(1, M+1) range 1 M+1 M 1 temp = 0 temp 0 if(S[i] == T[j]):
            temp = sum_dp[i-1][j-1] + 1
         S[i] == T[j] S[i] S i T[j] T j temp = sum_dp[i-1][j-1] + 1 temp sum_dp[i-1][j-1] + 1 sum_dp[i-1][j-1] [i-1] sum_dp i-1 i 1 j-1 j 1 1 sum_dp[i][j] = (sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + temp) sum_dp[i][j] [i] sum_dp i j sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + temp sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] sum_dp[i-1][j] + sum_dp[i][j-1] sum_dp[i-1][j] [i-1] sum_dp i-1 i 1 j sum_dp[i][j-1] [i] sum_dp i j-1 j 1 sum_dp[i-1][j-1] [i-1] sum_dp i-1 i 1 j-1 j 1 temp sum_dp[i][j] %= mod sum_dp[i][j] [i] sum_dp i j mod print(sum_dp[N][M] + 1) print sum_dp[N][M] + 1 sum_dp[N][M] [N] sum_dp N M 1 temp = sum_dp[i-1][j-1] + 1 sum_dp[i-1][j-1] + 1 temp sum_dp = [] [] sum_dp temp = 0 0 temp M = map(int, input().split()) map(int, input().split()) M mod = 10 ** 9 + 7 10 ** 9 + 7 mod N, M = map(int, input().split()) map(int, input().split()) N S = [0] + list(map(int, input().split())) [0] + list(map(int, input().split())) S T = [0] + list(map(int, input().split())) [0] + list(map(int, input().split())) T
from collections import defaultdict

N, M = map(int, input().split())
S = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
mod = 10 ** 9 + 7
sum_dp = []
for i in range(N+1):
    sum_dp.append([0] * (M+1))

for i in range(1, N+1):
    for j in range(1, M+1):
        temp = 0
        if(S[i] == T[j]):
            temp = sum_dp[i-1][j-1] + 1
        sum_dp[i][j] = (sum_dp[i-1][j] + sum_dp[i][j-1] - sum_dp[i-1][j-1] + temp)
        sum_dp[i][j] %= mod
        
print(sum_dp[N][M] + 1)
