#include <iostream>
#include<math.h>
using namespace std;
const int N=2e3+10;
int a[N],b[N];
int dp[N][N];
const int mod=1e9+7;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1; i<=n; i++) cin>>a[i];
    for(int j=1; j<=m; j++) cin>>b[j];
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
          dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod;
                if(a[i]==b[j])
                    dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % mod + 1;
                dp[i][j]%=mod;
        }
    }
     cout<<(dp[n][m]+mod)%mod+1<<endl;
    return 0;
}
