import sys
sys.setrecursionlimit(10**7)

mod = 10**9 + 7

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

dp = [[0]*(M+1) for _ in range(N+1)]

def rec(i,j):
    if dp[i][j] != 0:
        return dp[i][j]
    if (i == 0 or j == 0):
        dp[i][j] = 1
        return 1
    if S[i-1] == T[j-1]:
        res = rec(i,j-1) + rec(i-1,j)
    else:
        res = rec(i,j-1) + rec(i-1,j) - rec(i-1,j-1)
    res %= mod
    dp[i][j] = res
    return res

ans = rec(N,M)
print(ans)