#include <bits/stdc++.h>

using namespace std;
const int mod = 1e9+7;
const int maxn = 2e3+23;
const int maxm = 1e5+15;
int n,m,a[maxn],b[maxn];
long long dp[maxn][maxn],sum[maxn];
int main(){
    cin >> n >> m;
    for(int i = 0;i <= n; ++i) dp[i][0] = 1;
    for(int i = 0;i <= m; ++i) dp[0][i] = 1;
    for(int i = 1;i <= n; ++i) cin >> a[i];
    for(int i = 1;i <= m; ++i) cin >> b[i];
    for(int i = 1;i <= n; ++i){
        for(int j = 1;j <= m; ++j){
            if(a[i] == b[j]) sum[j-1] = (sum[j-1]+dp[i-1][j-1])%mod;
            dp[i][j] = (dp[i][j-1] + sum[j-1])%mod;
        }
    }
    cout << dp[n][m];
    return 0;
}