#pragma GCC optimize("O3")

#include<iostream>

using namespace std;
typedef unsigned int ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007 //10^9+7:合同式の法


ll s[2001],t[2001],dp[2001][2001],n,m={0};

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    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+1][j+1]+=dp[i][j+1];
            if(s[i]!=t[j])dp[i+1][j+1]+=(MOD-dp[i][j]);
            dp[i+1][j+1]%=MOD;
        }
    }
    cout<<dp[n][m]<<"\n";
}