#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int md = 1e9+7;
const int mx = 2005;
int n, m, s[mx] = {-1}, t[mx] = {-2};
long long dp[mx][mx];
int main(){
    scanf("%d%d", &n, &m);
    rep(i,n) scanf("%d", s+i+1);
    rep(i,m) scanf("%d", t+i+1);
    rep(i,n+1) dp[i][0] = 1;
    rep(i,m+1) dp[0][i] = 1;
    for(int i = 1; i <= n; i++){
        long long tmp = 0;
        for(int j = 1; j <= m; j++){
            if(s[i] == t[j]) (tmp += dp[i-1][j-1]) %= md;
            dp[i][j] = (dp[i-1][j] + tmp) % md;
        }
    }
    printf("%lld\n", dp[n][m]);
}