n,m=[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
mod=10**9+7
dp=[[0]*(m+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n+1):
    for j in range(m+1):
        if i!=0:
            dp[i][j]+=dp[i-1][j]
        if j!=0:
            dp[i][j]+=dp[i][j-1]
        if i!=0 and j!=0:
            if s[i-1]!=t[j-1]:
                dp[i][j]-=dp[i-1][j-1]
        dp[i][j]%=mod
print(dp[-1][-1]) int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n,m=[int(i) for i in input().split()] n [int(i) for i in input().split()] m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i s=[int(i) for i in input().split()] s [int(i) for i in input().split()] int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i t=[int(i) for i in input().split()] t [int(i) for i in input().split()] mod=10**9+7 mod 10**9+7 10**9 10 9 7 [0]*(m+1) for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [0]*(m+1) [0] 0 m+1 m 1 dp=[[0]*(m+1) for i in range(n+1)] dp [[0]*(m+1) for i in range(n+1)] dp[0][0]=1 dp[0][0] [0] dp 0 0 1 for i in range(n+1):
    for j in range(m+1):
        if i!=0:
            dp[i][j]+=dp[i-1][j]
        if j!=0:
            dp[i][j]+=dp[i][j-1]
        if i!=0 and j!=0:
            if s[i-1]!=t[j-1]:
                dp[i][j]-=dp[i-1][j-1]
        dp[i][j]%=mod i range(n+1) range n+1 n 1 for j in range(m+1):
        if i!=0:
            dp[i][j]+=dp[i-1][j]
        if j!=0:
            dp[i][j]+=dp[i][j-1]
        if i!=0 and j!=0:
            if s[i-1]!=t[j-1]:
                dp[i][j]-=dp[i-1][j-1]
        dp[i][j]%=mod j range(m+1) range m+1 m 1 if i!=0:
            dp[i][j]+=dp[i-1][j]
         i!=0 i 0 dp[i][j]+=dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j if j!=0:
            dp[i][j]+=dp[i][j-1]
         j!=0 j 0 dp[i][j]+=dp[i][j-1] dp[i][j] [i] dp i j dp[i][j-1] [i] dp i j-1 j 1 if i!=0 and j!=0:
            if s[i-1]!=t[j-1]:
                dp[i][j]-=dp[i-1][j-1]
         i!=0 and j!=0 i!=0 i 0 j!=0 j 0 if s[i-1]!=t[j-1]:
                dp[i][j]-=dp[i-1][j-1]
         s[i-1]!=t[j-1] s[i-1] s i-1 i 1 t[j-1] t j-1 j 1 dp[i][j]-=dp[i-1][j-1] dp[i][j] [i] dp i j dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 dp[i][j]%=mod dp[i][j] [i] dp i j mod print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 n,m=[int(i) for i in input().split()] [int(i) for i in input().split()] n m=[int(i) for i in input().split()] [int(i) for i in input().split()] m s=[int(i) for i in input().split()] [int(i) for i in input().split()] s dp=[[0]*(m+1) for i in range(n+1)] [[0]*(m+1) for i in range(n+1)] dp mod=10**9+7 10**9+7 mod t=[int(i) for i in input().split()] [int(i) for i in input().split()] t
n,m=[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
mod=10**9+7
dp=[[0]*(m+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n+1):
    for j in range(m+1):
        if i!=0:
            dp[i][j]+=dp[i-1][j]
        if j!=0:
            dp[i][j]+=dp[i][j-1]
        if i!=0 and j!=0:
            if s[i-1]!=t[j-1]:
                dp[i][j]-=dp[i-1][j-1]
        dp[i][j]%=mod
print(dp[-1][-1])