#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=2e3+10;
const ll mod=1e9+7;
int s[mn],t[mn];
ll dp[mn][mn];
int main(){
    int n,m,i,j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)scanf("%d",s+i),dp[i][0]=1;
    for(i=1;i<=m;i++)scanf("%d",t+i),dp[0][i]=1;
    dp[0][0]=1;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
            if(s[i]==t[j])dp[i][j]+=dp[i-1][j-1];
            dp[i][j]%=mod;
        }
    }
    if(dp[n][m]<0)dp[n][m]+=mod;
    printf("%lld",dp[n][m]);
}
