#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> S(N),T(M);
	for(auto &s:S) cin >> s;
	for(auto &t:T) cin >> t;
	ll sum[N+2][M+2]={},dp[N+1][M+1]={};
	for(int i=0;i<N+1;i++)sum[i][0] = 1;
	for(int i=0;i<M+1;i++)sum[0][i] = 1;
	for(int i=1;i<N+1;i++){
		for(int j=1;j<M+1;j++){		
			dp[i][j] = sum[i-1][j-1]*(S[i-1]==T[j-1]);
			sum[i][j] = (sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%MOD;
		}
	}
	cout << sum[N][M] << endl;
}