#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n,m;cin>>n>>m;
    vector<int>S(n),T(m);rep(i,n)cin>>S[i];
    rep(i,m)cin>>T[i];
    vector<vector<int>>dp(n+1,vector<int>(m+1,1));
    rep(i,n)rep(j,m){
        if(S[i]==T[j])dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%mod;
        else dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j])%mod;
    }
    cout<<(dp[n][m]+mod)%mod<<endl;
}
