
# start:2020-05-28 00:22:02
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

MOD = 10**9+7
dp = [[0]*(M+1) for _ in range(N+1)]
rui = [[0]*(M+1) for _ in range(N+1)]
ans = 1
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i+1][j+1] = rui[i][j] + 1
            dp[i+1][j+1] %= MOD
            ans += dp[i+1][j+1]
            ans %= MOD    
        rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] - rui[i][j] + dp[i+1][j+1]
        rui[i+1][j+1] %= MOD

print(ans) import sys sys sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 [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 rui = [[0]*(M+1) for _ in range(N+1)] rui [[0]*(M+1) for _ in range(N+1)] ans = 1 ans 1 for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i+1][j+1] = rui[i][j] + 1
            dp[i+1][j+1] %= MOD
            ans += dp[i+1][j+1]
            ans %= MOD    
        rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] - rui[i][j] + dp[i+1][j+1]
        rui[i+1][j+1] %= MOD i range(N) range N for j in range(M):
        if S[i]==T[j]:
            dp[i+1][j+1] = rui[i][j] + 1
            dp[i+1][j+1] %= MOD
            ans += dp[i+1][j+1]
            ans %= MOD    
        rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] - rui[i][j] + dp[i+1][j+1]
        rui[i+1][j+1] %= MOD j range(M) range M if S[i]==T[j]:
            dp[i+1][j+1] = rui[i][j] + 1
            dp[i+1][j+1] %= MOD
            ans += dp[i+1][j+1]
            ans %= MOD    
         S[i]==T[j] S[i] S i T[j] T j dp[i+1][j+1] = rui[i][j] + 1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 rui[i][j] + 1 rui[i][j] [i] rui i j 1 dp[i+1][j+1] %= MOD dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 MOD ans += dp[i+1][j+1] ans dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 ans %= MOD ans MOD rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] - rui[i][j] + dp[i+1][j+1] rui[i+1][j+1] [i+1] rui i+1 i 1 j+1 j 1 rui[i+1][j] + rui[i][j+1] - rui[i][j] + dp[i+1][j+1] rui[i+1][j] + rui[i][j+1] - rui[i][j] rui[i+1][j] + rui[i][j+1] rui[i+1][j] [i+1] rui i+1 i 1 j rui[i][j+1] [i] rui i j+1 j 1 rui[i][j] [i] rui i j dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 rui[i+1][j+1] %= MOD rui[i+1][j+1] [i+1] rui i+1 i 1 j+1 j 1 MOD print(ans) print ans ans %= MOD MOD ans input = sys.stdin.readline sys.stdin.readline input T = list(map(int,input().split())) list(map(int,input().split())) T ans = 1 1 ans M = map(int,input().split()) map(int,input().split()) M N, M = map(int,input().split()) map(int,input().split()) N S = list(map(int,input().split())) list(map(int,input().split())) S MOD = 10**9+7 10**9+7 MOD rui = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] rui ans += dp[i+1][j+1] dp[i+1][j+1] ans dp = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] dp

# start:2020-05-28 00:22:02
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

MOD = 10**9+7
dp = [[0]*(M+1) for _ in range(N+1)]
rui = [[0]*(M+1) for _ in range(N+1)]
ans = 1
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i+1][j+1] = rui[i][j] + 1
            dp[i+1][j+1] %= MOD
            ans += dp[i+1][j+1]
            ans %= MOD    
        rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] - rui[i][j] + dp[i+1][j+1]
        rui[i+1][j+1] %= MOD

print(ans)