#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;

int N, M;
vector<int> S, T;
#include "Modulo.h"
#define MOD 1000000007

vector<vector<bool>> memo;
vector<vector<Modint>> dp;

Modint dfs(int i, int j) {
	if (memo[i][j])
		return dp[i][j];
	Modint test1 = dfs(i - 1, j);
	Modint test2 = dfs(i, j - 1);
	Modint test3 = S[i] == T[j] ? 0 : dfs(i - 1, j - 1);
	const Modint res = dfs(i - 1, j) + dfs(i, j - 1) - ((S[i] == T[j]) ? 0 : dfs(i - 1, j - 1));
	dp[i][j] = res;
	memo[i][j] = true;
	return res;
}

int main() {
	cin >> N >> M;
	S = vector<int>(N+1), T = vector<int>(M+1);
	for (int i = 1; i <= N; i++)
		cin >> S[i];
	for (int j = 1; j <= M; j++)
		cin >> T[j];
	set_mod(MOD);

	memo = vector<vector<bool>>(N + 1, vector<bool>(M + 1, false));
	dp = vector<vector<Modint>>(N + 1, vector<Modint>(M + 1, 0));
	for (int i = 0; i <= N; i++)
	{
		memo[i][0] = true;
		dp[i][0] = 1;
	}
	for (int j = 0; j <= M; j++)
	{
		memo[0][j] = true;
		dp[0][j] = 1;
	}

	Modint ans = dfs(N, M);
	cout << ans << endl;
	return 0;
}
