
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[0][0]=1
    #dp[i][j]はSのi文字目，Tのj文字目を使う時の通り数
    cumsum=[[0]*(M+2) for _ in range(N+2)]
    #2D累積和
    
    for i in range(1,N+2):
        cumsum[i][1]=1
    for j in range(1,M+2):
        cumsum[1][j]=1
    
    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
            cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod
            
    print(cumsum[-1][-1])
    """
    for i in range(N+2):
        print(' '.join(map(str, cumsum[i])))
        
    for i in range(N+1):
        print(' '.join(map(str, dp[i])))"""

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[0][0]=1
    #dp[i][j]はSのi文字目，Tのj文字目を使う時の通り数
    cumsum=[[0]*(M+2) for _ in range(N+2)]
    #2D累積和
    
    for i in range(1,N+2):
        cumsum[i][1]=1
    for j in range(1,M+2):
        cumsum[1][j]=1
    
    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
            cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod
            
    print(cumsum[-1][-1])
    """
    for i in range(N+2):
        print(' '.join(map(str, cumsum[i])))
        
    for i in range(N+1):
        print(' '.join(map(str, dp[i])))""" 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)] dp[0][0]=1 dp[0][0] [0] dp 0 0 1 [0]*(M+2) for _ in range(N+2) for _ in range(N+2) _ range(N+2) range N+2 N 2 for _ in range(N+2) [0]*(M+2) [0] 0 M+2 M 2 cumsum=[[0]*(M+2) for _ in range(N+2)] cumsum [[0]*(M+2) for _ in range(N+2)] for i in range(1,N+2):
        cumsum[i][1]=1
     i range(1,N+2) range 1 N+2 N 2 cumsum[i][1]=1 cumsum[i][1] [i] cumsum i 1 1 for j in range(1,M+2):
        cumsum[1][j]=1
    
     j range(1,M+2) range 1 M+2 M 2 cumsum[1][j]=1 cumsum[1][j] [1] cumsum 1 j 1 for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
            cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod
            
     i range(N) range N for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
            cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod
            
     j range(M) range M if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
             S[i]==T[j] S[i] S i T[j] T j dp[i+1][j+1]=(cumsum[i+1][j+1])%mod dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 (cumsum[i+1][j+1])%mod cumsum[i+1][j+1] [i+1] cumsum i+1 i 1 j+1 j 1 mod cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod cumsum[i+2][j+2] [i+2] cumsum i+2 i 2 j+2 j 2 (cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1] cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1] cumsum[i+2][j+1]+cumsum[i+1][j+2] cumsum[i+2][j+1] [i+2] cumsum i+2 i 2 j+1 j 1 cumsum[i+1][j+2] [i+1] cumsum i+1 i 1 j+2 j 2 cumsum[i+1][j+1] [i+1] cumsum i+1 i 1 j+1 j 1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 mod print(cumsum[-1][-1]) print cumsum[-1][-1] [-1] cumsum -1 -1 """
    for i in range(N+2):
        print(' '.join(map(str, cumsum[i])))
        
    for i in range(N+1):
        print(' '.join(map(str, dp[i])))""" main() 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 main():
    mod=10**9+7
    N,M=MI()
    S=LI()
    T=LI()
    
    dp=[[0]*(M+1) for _ in range(N+1)]
    dp[0][0]=1
    #dp[i][j]はSのi文字目，Tのj文字目を使う時の通り数
    cumsum=[[0]*(M+2) for _ in range(N+2)]
    #2D累積和
    
    for i in range(1,N+2):
        cumsum[i][1]=1
    for j in range(1,M+2):
        cumsum[1][j]=1
    
    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
            cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod
            
    print(cumsum[-1][-1])
    """
    for i in range(N+2):
        print(' '.join(map(str, cumsum[i])))
        
    for i in range(N+1):
        print(' '.join(map(str, dp[i])))""" def main():
    mod=10**9+7
    N,M=MI()
    S=LI()
    T=LI()
    
    dp=[[0]*(M+1) for _ in range(N+1)]
    dp[0][0]=1
    #dp[i][j]はSのi文字目，Tのj文字目を使う時の通り数
    cumsum=[[0]*(M+2) for _ in range(N+2)]
    #2D累積和
    
    for i in range(1,N+2):
        cumsum[i][1]=1
    for j in range(1,M+2):
        cumsum[1][j]=1
    
    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
            cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod
            
    print(cumsum[-1][-1])
    """
    for i in range(N+2):
        print(' '.join(map(str, cumsum[i])))
        
    for i in range(N+1):
        print(' '.join(map(str, dp[i])))""" main def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI

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[0][0]=1
    #dp[i][j]はSのi文字目，Tのj文字目を使う時の通り数
    cumsum=[[0]*(M+2) for _ in range(N+2)]
    #2D累積和
    
    for i in range(1,N+2):
        cumsum[i][1]=1
    for j in range(1,M+2):
        cumsum[1][j]=1
    
    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(cumsum[i+1][j+1])%mod
                
            cumsum[i+2][j+2]=(cumsum[i+2][j+1]+cumsum[i+1][j+2]-cumsum[i+1][j+1]+dp[i+1][j+1])%mod
            
    print(cumsum[-1][-1])
    """
    for i in range(N+2):
        print(' '.join(map(str, cumsum[i])))
        
    for i in range(N+1):
        print(' '.join(map(str, dp[i])))"""

main()
