from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
dp = [[0]*(M+1) for i in range(N+1)]

for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m]

print((dp[N][M]+1)%mod) from itertools import* from math import* from collections import* from heapq import* from bisect import bisect_left,bisect_right from copy import deepcopy inf = float("inf") inf float("inf") float "inf" mod = 10**9+7 mod 10**9+7 10**9 10 9 7 from functools import reduce import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 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 i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [0]*(M+1) [0] 0 M+1 M 1 dp = [[0]*(M+1) for i in range(N+1)] dp [[0]*(M+1) for i in range(N+1)] for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m] n range(N) range N for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m] m range(M) range M if S[n] == T[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m] S[n] == T[m] S[n] S n T[m] T m dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod dp[n+1][m+1] [n+1] dp n+1 n 1 m+1 m 1 (dp[n+1][m]+dp[n][m+1]+1)%mod dp[n+1][m]+dp[n][m+1]+1 dp[n+1][m]+dp[n][m+1] dp[n+1][m] [n+1] dp n+1 n 1 m dp[n][m+1] [n] dp n m+1 m 1 1 mod dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m] dp[n+1][m+1] [n+1] dp n+1 n 1 m+1 m 1 dp[n+1][m]+dp[n][m+1]-dp[n][m] dp[n+1][m]+dp[n][m+1] dp[n+1][m] [n+1] dp n+1 n 1 m dp[n][m+1] [n] dp n m+1 m 1 dp[n][m] [n] dp n m 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 mod = 10**9+7 10**9+7 mod S = list(map(int,input().split())) list(map(int,input().split())) S M = map(int,input().split()) map(int,input().split()) M inf = float("inf") float("inf") inf T = list(map(int,input().split())) list(map(int,input().split())) T N,M = map(int,input().split()) map(int,input().split()) N dp = [[0]*(M+1) for i in range(N+1)] [[0]*(M+1) for i in range(N+1)] dp
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
dp = [[0]*(M+1) for i in range(N+1)]

for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m]

print((dp[N][M]+1)%mod)