#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repf(i, a, b) for(ll i = (a); i < (b) ; i++ )
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;
ll dp[2010][2010]={};

int main()
{
ll n,m;
cin >> n>>m;
ll s[n] = {};
rep(i, n){
    cin >> s[i];
}
ll t[m] = {};
rep(i, m){
    cin >> t[i];
}
ll dp[m+1][n+1]={};

rep(i,m+1){
    dp[i][0]=1;
}
rep(i,n+1){
    dp[0][i]=1;
}
rep(i,m)rep(j,n){
    dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j]-dp[i][j];
    if(s[j]==t[i]){
        dp[i+1][j+1]+=dp[i][j];
        
    }
    dp[i+1][j+1]%=mo;
}
cout << dp[m][n] << endl;

return 0;
}