
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    S=LI()
    T=LI()

    dp=[[0]*(M+1) for _ in range(N+1)]
    # dp[i][j]はSをi文字，Tをj文字見た時の通り数
    
    for i in range(N+1):
        dp[i][0]=1
        
    for j in range(M+1):
        dp[0][j]=1
    
    for i in range(N):
        for j in range(M):
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
            dp[i+1][j+1]%=mod
            
            
    print(dp[-1][-1])
            
                
            
    

    

main() def I(): return int(input()) I def MI(): return map(int, input().split()) MI def LI(): return list(map(int, input().split())) LI def main():
    mod=10**9+7
    N,M=MI()
    S=LI()
    T=LI()

    dp=[[0]*(M+1) for _ in range(N+1)]
    # dp[i][j]はSをi文字，Tをj文字見た時の通り数
    
    for i in range(N+1):
        dp[i][0]=1
        
    for j in range(M+1):
        dp[0][j]=1
    
    for i in range(N):
        for j in range(M):
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
            dp[i+1][j+1]%=mod
            
            
    print(dp[-1][-1])
            
                
            
    

     main mod=10**9+7 mod 10**9+7 10**9 10 9 7 N,M=MI() N MI() MI M S=LI() S LI() LI T=LI() T LI() LI [0]*(M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0]*(M+1) [0] 0 M+1 M 1 dp=[[0]*(M+1) for _ in range(N+1)] dp [[0]*(M+1) for _ in range(N+1)] for i in range(N+1):
        dp[i][0]=1
        
     i range(N+1) range N+1 N 1 dp[i][0]=1 dp[i][0] [i] dp i 0 1 for j in range(M+1):
        dp[0][j]=1
    
     j range(M+1) range M+1 M 1 dp[0][j]=1 dp[0][j] [0] dp 0 j 1 for i in range(N):
        for j in range(M):
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
            dp[i+1][j+1]%=mod
            
            
     i range(N) range N for j in range(M):
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
            dp[i+1][j+1]%=mod
            
            
     j range(M) range M dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i+1][j]+dp[i][j+1] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j+1] [i] dp i j+1 j 1 if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
             S[i]!=T[j] S[i] S i T[j] T j dp[i+1][j+1]-=dp[i][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i][j] [i] dp i j dp[i+1][j+1]%=mod dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 mod print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 main() main def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI def main():
    mod=10**9+7
    N,M=MI()
    S=LI()
    T=LI()

    dp=[[0]*(M+1) for _ in range(N+1)]
    # dp[i][j]はSをi文字，Tをj文字見た時の通り数
    
    for i in range(N+1):
        dp[i][0]=1
        
    for j in range(M+1):
        dp[0][j]=1
    
    for i in range(N):
        for j in range(M):
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
            dp[i+1][j+1]%=mod
            
            
    print(dp[-1][-1])
            
                
            
    

     def main():
    mod=10**9+7
    N,M=MI()
    S=LI()
    T=LI()

    dp=[[0]*(M+1) for _ in range(N+1)]
    # dp[i][j]はSをi文字，Tをj文字見た時の通り数
    
    for i in range(N+1):
        dp[i][0]=1
        
    for j in range(M+1):
        dp[0][j]=1
    
    for i in range(N):
        for j in range(M):
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
            dp[i+1][j+1]%=mod
            
            
    print(dp[-1][-1])
            
                
            
    

     main def I(): return int(input()) def I(): return int(input()) I def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    S=LI()
    T=LI()

    dp=[[0]*(M+1) for _ in range(N+1)]
    # dp[i][j]はSをi文字，Tをj文字見た時の通り数
    
    for i in range(N+1):
        dp[i][0]=1
        
    for j in range(M+1):
        dp[0][j]=1
    
    for i in range(N):
        for j in range(M):
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            if S[i]!=T[j]:
                dp[i+1][j+1]-=dp[i][j]
            dp[i+1][j+1]%=mod
            
            
    print(dp[-1][-1])
            
                
            
    

    

main()
