n, m = map(int, input().split())
ss = input()
ts = input()
d = [[1] * (m+1) for _ in range(n+1)]
for i in range(n):
    for j in range(m):
        d[i+1][j+1] = d[i][j+1] + d[i+1][j] - (ss[2*i] != ts[2*j])*d[i][j]
print(d[n][m]%(10**9+7))