#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<int> S(N);
    vector<int> T(M);
    rep(i,0,N)cin >> S[i];
    rep(i,0,M)cin >> T[i];
    vector<int> vec[2010];
    rep(i,0,N){
        if(vec[S[i]].size())continue;
        rep(j,0,M){
            if(S[i] == T[j])vec[S[i]].push_back(j+1);
        }
    }
    /*
    cout << endl;
    rep(i,0,N){
        rep(j,0,vec[S[i]].size())cout << vec[S[i]][j] << " ";cout << endl;
    }
    */
    ll dp[N+1][M+1] = {};
    dp[0][0] = 1;
    rep(i,0,N){
        rep(j,0,M+1){
            dp[i+1][j] += dp[i][j];
        }
        vector<ll> accum(M+2);
        rep(j,0,M+1){
            accum[j+1] = (accum[j] + dp[i][j]) % MOD;
        }
        for(auto j:vec[S[i]]){
            ll cnt = 0;
            /*
            rep(k,0,j){
                cnt += dp[i][k];
            }
            */
           
            dp[i+1][j] += accum[j];
            dp[i+1][j] %= MOD;
        }
    }
    ll ans = 0;
    rep(i,0,M+1){
        ans += dp[N][i];
        ans %= MOD;
    }
    /*
    rep(i,0,N+1)rep(j,0,M+1){
        cout << dp[i][j] << " \n"[j==M];
    }
    */
    cout << ans << endl;
}