(n,m),s,t=map(int,input().split()),input(),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]-(s[2*i]!=t[2*j])*d[i][j]
print(d[n][m]%(10**9+7))
