
def valide(i,A):
    return 0<=i and i <= A

N = 0
M = 0
N, M = input().split()
N = int(N)
M = int(M)
#print(N, M)
S = input().split()
T = input().split()
#print(S)
#print(T)

DP = [[0 for x in range(M)] for y in range(N)]
curr = 0
for i in range(N):
    if S[i] == T[0]:
        curr = curr + 1
        DP[i][0] = curr+1
    DP[i][0] = curr+1
curr = 0
for j in range(M):
    if T[j] == S[0]:
        curr = curr + 1
        DP[0][j] = curr+1
    DP[0][j] = curr+1


#print(DP)
for i in range(1,N):
    for j in range(1,M):
        if S[i] == T[j]:
            DP[i][j] = DP[i][j-1] + DP[i-1][j]
        else:
            DP[i][j] = DP[i][j-1] + DP[i-1][j]-DP[i-1][j-1]
    
print(DP[N-1][M-1] % (7+(10**9)))
            
            
            
            
            
            
            
            
            
            
            
            
            

