#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
ll dp[2002][2002];
int n,m;
int s[2002],t[2002];
int main(){
    cin>>n>>m;
    rep(i,n) cin>>s[i];
    rep(i,m) cin>>t[i];
    rep(i,n+1) dp[i][0]=1;
    rep(i,m+1) dp[0][i]=1;
    rep(i,n)rep(j,m){
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]+mod-dp[i][j]%mod;
        if(s[i]==t[j]){
            dp[i+1][j+1]+=dp[i][j]%mod;
        }
        dp[i+1][j+1]%=mod;
    }
    cout<<dp[n][m]<<endl;
    return 0;
}
