//参考:http://kmjp.hatenablog.jp/entry/2019/06/17/0930  ムズかしい.....><
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(void){
    int n,m; cin>>n>>m;
    vector <ll> s(n), t(m);
    rep(i,n) cin>>s[i];
    rep(i,m) cin>>t[i];
    vector <vector<ll>> dp(2019 ,vector <ll>(2019 ));
    vector <vector<ll>> sum(2019 ,vector <ll>(2019));
    rep(i,2019) sum[i][0]=sum[0][i]=1;
    ll ans = 1;
    rep(i,n) rep(j,m){
        if(s[i]==t[j]) {dp[i+1][j+1] = sum[i][j]%MOD; ans += dp[i+1][j+1]; ans %= MOD}
        sum[i+1][j+1] = (sum[i+1][j]%MOD + sum[i][j+1]%MOD + dp[i+1][j+1]%MOD - sum[i][j]) %MOD;
    }
    cout<<ans%MOD<<endl;
}
