MOD = 10**9 + 7
N, M = map(int, input().split())
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]

dp = [[0 for j in range(2010)] for i in range(2010)]
dp[0][0] = 1
for s in range(N+1):
    for t in range(M+1):
        if 0 < s and 0 < t and S[s-1] == T[t-1]:
            dp[s][t] += dp[s-1][t-1]
        if 0 < s:
            dp[s][t] += dp[s-1][t]
        if 0 < t:
            dp[s][t] += dp[s][t-1]
        if 0 < s and 0 < t:
            dp[s][t] -= dp[s-1][t-1]
        dp[s][t] %= MOD
print(dp[N][M]) 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 int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i S = [int(i) for i in input().split()] S [int(i) for i in input().split()] int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i T = [int(i) for i in input().split()] T [int(i) for i in input().split()] [0 for j in range(2010)] for i in range(2010) for i in range(2010) i range(2010) range 2010 for i in range(2010) [0 for j in range(2010)] dp = [[0 for j in range(2010)] for i in range(2010)] dp [[0 for j in range(2010)] for i in range(2010)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for s in range(N+1):
    for t in range(M+1):
        if 0 < s and 0 < t and S[s-1] == T[t-1]:
            dp[s][t] += dp[s-1][t-1]
        if 0 < s:
            dp[s][t] += dp[s-1][t]
        if 0 < t:
            dp[s][t] += dp[s][t-1]
        if 0 < s and 0 < t:
            dp[s][t] -= dp[s-1][t-1]
        dp[s][t] %= MOD s range(N+1) range N+1 N 1 for t in range(M+1):
        if 0 < s and 0 < t and S[s-1] == T[t-1]:
            dp[s][t] += dp[s-1][t-1]
        if 0 < s:
            dp[s][t] += dp[s-1][t]
        if 0 < t:
            dp[s][t] += dp[s][t-1]
        if 0 < s and 0 < t:
            dp[s][t] -= dp[s-1][t-1]
        dp[s][t] %= MOD t range(M+1) range M+1 M 1 if 0 < s and 0 < t and S[s-1] == T[t-1]:
            dp[s][t] += dp[s-1][t-1]
         0 < s and 0 < t and S[s-1] == T[t-1] 0 < s and 0 < t 0 < s 0 s 0 < t 0 t S[s-1] == T[t-1] S[s-1] S s-1 s 1 T[t-1] T t-1 t 1 dp[s][t] += dp[s-1][t-1] dp[s][t] [s] dp s t dp[s-1][t-1] [s-1] dp s-1 s 1 t-1 t 1 if 0 < s:
            dp[s][t] += dp[s-1][t]
         0 < s 0 s dp[s][t] += dp[s-1][t] dp[s][t] [s] dp s t dp[s-1][t] [s-1] dp s-1 s 1 t if 0 < t:
            dp[s][t] += dp[s][t-1]
         0 < t 0 t dp[s][t] += dp[s][t-1] dp[s][t] [s] dp s t dp[s][t-1] [s] dp s t-1 t 1 if 0 < s and 0 < t:
            dp[s][t] -= dp[s-1][t-1]
         0 < s and 0 < t 0 < s 0 s 0 < t 0 t dp[s][t] -= dp[s-1][t-1] dp[s][t] [s] dp s t dp[s-1][t-1] [s-1] dp s-1 s 1 t-1 t 1 dp[s][t] %= MOD dp[s][t] [s] dp s t MOD print(dp[N][M]) print dp[N][M] [N] dp N M M = map(int, input().split()) map(int, input().split()) M S = [int(i) for i in input().split()] [int(i) for i in input().split()] S N, M = map(int, input().split()) map(int, input().split()) N T = [int(i) for i in input().split()] [int(i) for i in input().split()] T dp = [[0 for j in range(2010)] for i in range(2010)] [[0 for j in range(2010)] for i in range(2010)] dp MOD = 10**9 + 7 10**9 + 7 MOD
MOD = 10**9 + 7
N, M = map(int, input().split())
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]

dp = [[0 for j in range(2010)] for i in range(2010)]
dp[0][0] = 1
for s in range(N+1):
    for t in range(M+1):
        if 0 < s and 0 < t and S[s-1] == T[t-1]:
            dp[s][t] += dp[s-1][t-1]
        if 0 < s:
            dp[s][t] += dp[s-1][t]
        if 0 < t:
            dp[s][t] += dp[s][t-1]
        if 0 < s and 0 < t:
            dp[s][t] -= dp[s-1][t-1]
        dp[s][t] %= MOD
print(dp[N][M])
