MOD=1000000007
n,m=map(int,input().split())

S=[int(_) for _ in input().split()]
T=[int(_) for _ in input().split()]

dp=[[0 for j in range(m+1)] for i in range(n+1)]
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):
        if S[i]!=T[j]:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]
            dp[i+1][j+1]%=MOD
        else:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            dp[i+1][j+1]%=MOD
print((dp[n][m])%MOD) MOD=1000000007 MOD 1000000007 n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ S=[int(_) for _ in input().split()] S [int(_) for _ in input().split()] int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ T=[int(_) for _ in input().split()] T [int(_) for _ in input().split()] [0 for j in range(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 for j in range(m+1)] dp=[[0 for j in range(m+1)] for i in range(n+1)] dp [[0 for j in range(m+1)] for i 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):
        if S[i]!=T[j]:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]
            dp[i+1][j+1]%=MOD
        else:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][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]=dp[i+1][j]+dp[i][j+1]-dp[i][j]
            dp[i+1][j+1]%=MOD
        else:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            dp[i+1][j+1]%=MOD j range(m) range m if S[i]!=T[j]:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]
            dp[i+1][j+1]%=MOD
        else:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            dp[i+1][j+1]%=MOD S[i]!=T[j] S[i] S i T[j] T j dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j] 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] 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 dp[i+1][j+1]%=MOD dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 MOD 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 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[n][m])%MOD) print (dp[n][m])%MOD dp[n][m] [n] dp n m MOD n,m=map(int,input().split()) map(int,input().split()) n MOD=1000000007 1000000007 MOD S=[int(_) for _ in input().split()] [int(_) for _ in input().split()] S T=[int(_) for _ in input().split()] [int(_) for _ in input().split()] T dp=[[0 for j in range(m+1)] for i in range(n+1)] [[0 for j in range(m+1)] for i in range(n+1)] dp m=map(int,input().split()) map(int,input().split()) m
MOD=1000000007
n,m=map(int,input().split())

S=[int(_) for _ in input().split()]
T=[int(_) for _ in input().split()]

dp=[[0 for j in range(m+1)] for i in range(n+1)]
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):
        if S[i]!=T[j]:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]
            dp[i+1][j+1]%=MOD
        else:
            dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
            dp[i+1][j+1]%=MOD
print((dp[n][m])%MOD)