#include <iostream>
#include <limits>
#include <cmath>
#include <cstdio>

#define pf printf
// #define DEBUG true
#define DEBUG false
#define IFD if(DEBUG)
#define FOR(i,ii,n) for(long long i=ii; i<n; i++)
#define FORREV(i,ii,n) for(long long i=n-1; i>=ii; i--)
#define INF ((ll)1e15)

using namespace std;
typedef long long ll;

// ll const NMAX = 4001;
ll const NMAX = 41;
// ll mod = 998244353;
ll mod = 1e9 + 7;
ll fact[NMAX];
ll finv[NMAX];
ll comb(ll n,ll a){
	return fact[n] * finv[a] % mod * finv[n-a] % mod;
}
ll numk[NMAX];

void ppdp(ll N, ll M, ll dp[NMAX][NMAX]){
	FOR(i,0,N){
		FOR(j,0,M){
			printf("%lld ",dp[i][j]);
		}
		printf("\n");
	}
}

// 配列大きさ1000000レベルだとwandboxでsegfaultが起こる
// ll のprintfは%lld
int main(){
	ll N;
	ll M;
	ll S[NMAX];
	ll T[NMAX];
	ll DP[NMAX][NMAX];
	ll SUM[NMAX];
	ll SUMmin1[NMAX];
	// init
	cin >> N;
	cin >> M;
	// printf("%lld\n",hoge);
	FOR(i,0,N){
		cin >> S[i];
	}
	FOR(i,0,M){
		cin >> T[i];
	}
	FOR(s,0,N){
		SUMmin1[0] = SUM[0];
		if(S[s]==T[0]){
			DP[s][0] = 1;
			SUM[0] += 1;
		}
		FOR(t,1,M){
			DP[s][t] = DP[s][t-1];
			if(S[s]==T[t]){
				DP[s][t] += SUMmin1[t-1]+1;
			}
			SUMmin1[t] = SUM[t];
			SUM[t] += DP[s][t];
		}
	}
	// 最後にmodとってみるテスト
	ll hoge = (SUM[M-1]+1)%mod;
	// ppdp(N,M,DP);
	printf("%lld\n",hoge);
}

