#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

signed main(){
	int N, M, i, j;
	scanf("%lld%lld", &N, &M);
	vector<int> S(N + 1), T(M + 1);
	for(i = 1; i <= N; i++){
		scanf("%lld", &S[i]);
	}
	for(j = 1; j <= M; j++){
		scanf("%lld", &T[j]);
	}
	vector<vector<int>> dp(N + 1, vector<int>(M + 1, 1));
	for(i = 1; i <= N; i++){
		for(j = 1; j <= M; j++){
			dp[i][j] = MOD(dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]);
			if(S[i] == T[j]){
				dp[i][j] = MOD(dp[i][j] + dp[i - 1][j - 1]);
			}
		}
	}
	printf("%lld\n", dp[N][M]);
	return 0;
}