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