def main():
    import numpy as np
    n,m=map(int,input().split())
    s=list(map(int,input().split()))
    t=list(map(int,input().split()))
    dp=np.zeros((n+1,m+1),dtype=np.int32)
    dp[:,m]=1
    dp[n,:]=1
    for i in range(n-1,-1,-1):
        temp=s[i]
        for j in range(m-1,-1,-1):
            if t[j]!=temp:
                dp[i,j]=(dp[i+1,j]+dp[i,j+1]-dp[i+1,j+1])%(10**9+7)
            else:
                dp[i,j]=(dp[i+1,j]+dp[i,j+1])%(10**9+7)
    print(dp[0,0])
main()