#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn = 2001;
const ll mof = 1e9+7;
ll dp[maxn][maxn];
ll s[maxn],t[maxn];
ll solve(int x,int y)
{
    if(dp[x][y]!=-1)
        return dp[x][y];
    if(s[x] == t[y])
    {
        dp[x][y] = (solve(x-1,y)+solve(x,y-1)) % mof;
    }else
    {
        dp[x][y] = (solve(x-1,y) + solve(x,y-1) - solve(x-1,y-1) + mof ) % mof;
    }
    return dp[x][y];
}
int main()
{
    int n,m;
    cin>>n>>m;
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;++i)cin>>s[i],dp[i][0] = 1;
    for(int i=1;i<=m;++i)cin>>t[i],dp[0][i] = 1;
    dp[0][0] = 1;
    cout<<solve(n,m)<<endl;
}