#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dp[2005][2005];
int a[2005],b[2005];
int n,m;
vector<int>index[MAX];
int recur(int l,int r)
{
    if(l>=n)
        return 0;
    int &ret=dp[l][r];
    if(~ret)
        return ret;
    ret=0;
    int cur=a[l];
    int sz=index[cur].size();
  //  cout<<l<<" "<<r<<endl;
    for(int i=0; i<sz; i++)
    {
        if(index[cur][i]>=r)
        {

            ret+=recur(l+1,index[cur][i]+1)+1;
            ret%=MOD;

        }
    }

    ret+=recur(l+1,r);
    ret%=MOD;
    return ret;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<m; i++)
    {
        cin>>b[i];
        index[b[i]].push_back(i);
    }
    memset(dp,-1,sizeof(dp));
    cout<<(recur(0,0)+1)%MOD<<endl;





    return 0;
}
