#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = pow(10,9) + 7;

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> S(N),T(M);
	for(ll i(0);i<N;++i){
		cin >> S[i];
	}
	for(ll i(0);i<M;++i){
		cin >> T[i];
	}
	ll dp[N][M],sum[N+1][M+1],ans(1);
	for(ll i(0);i<N+1;++i){
		for(ll j(0);j<M+1;++j){
			if(i == 0 || j == 0){
				sum[i][j] = 1;
			}else{
				if(S[i-1] != T[j-1]){
					dp[i-1][j-1] = 0;
				}else{
					dp[i-1][j-1] = sum[i-1][j-1]%MOD;
					ans += dp[i-1][j-1];
					ans %= MOD;
				}
				sum[i][j] = (sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + dp[i-1][j-1] + MOD)%MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}