#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=2e3+5;
int mul(int a,int b){return (long long)a*b;}
typedef long long ll;
int n,m,s[N],t[N];
int a[N];
ll dp[N][N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&s[i]);
    for(int i=1;i<=m;i++)
        scanf("%d",&t[i]);
    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(s[i]==t[j]) dp[i][j]+=dp[i-1][j-1]+1;
    }
    printf("%lld\n",(dp[n][m]%mod+1+mod)%mod);
}
