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

print((dp[n][m]+1)%mod) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () 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 for i in range(m+1)]for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) [0 for i in range(m+1)] dp=[[0 for i in range(m+1)]for j in range(n+1)] dp [[0 for i in range(m+1)]for j in range(n+1)] for i in range(n):
    for j in range(m):
        x=0
        if s[i]==t[j]:
            x=dp[i][j]+1
        dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+x)%mod i range(n) range n for j in range(m):
        x=0
        if s[i]==t[j]:
            x=dp[i][j]+1
        dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+x)%mod j range(m) range m x=0 x 0 if s[i]==t[j]:
            x=dp[i][j]+1
         s[i]==t[j] s[i] s i t[j] t j x=dp[i][j]+1 x dp[i][j]+1 dp[i][j] [i] dp i j 1 dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+x)%mod 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][j]+x)%mod dp[i+1][j]+dp[i][j+1]-dp[i][j]+x dp[i+1][j]+dp[i][j+1]-dp[i][j] 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 dp[i][j] [i] dp i j x mod print((dp[n][m]+1)%mod) print (dp[n][m]+1)%mod dp[n][m]+1 dp[n][m] [n] dp n m 1 mod n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m s=[int(i) for i in input().split()] [int(i) for i in input().split()] s x=0 0 x t=[int(i) for i in input().split()] [int(i) for i in input().split()] t mod=10**9+7 10**9+7 mod dp=[[0 for i in range(m+1)]for j in range(n+1)] [[0 for i in range(m+1)]for j in range(n+1)] dp x=dp[i][j]+1 dp[i][j]+1 x
n,m=map(int,input().split())
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
mod=10**9+7
dp=[[0 for i in range(m+1)]for j in range(n+1)]
for i in range(n):
    for j in range(m):
        x=0
        if s[i]==t[j]:
            x=dp[i][j]+1
        dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+x)%mod

print((dp[n][m]+1)%mod)
