#include <bits/stdc++.h>

constexpr int64_t mod{1'000'000'007};

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	using vi = std::vector<int>;
	vi S(N), T(M);
	for (auto& e: S) scanf("%d", &e);
	for (auto& e: T) scanf("%d", &e);

	using vi64 = std::vector<int64_t>;
	std::vector<vi64> dp(N + 1, vi64(M + 1));
	for (int i{}; i < N; i++)
		dp[i][M] = 1;
	for (int i{}; i <= M; i++)
		dp[N][i] = 1;
	for (int i{N - 1}; i >= 0; i--)
	{
		for (int j{M - 1}; j >= 0; j--)
		{
			dp[i][j] = (dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1]) % mod;
			if (S[i] != T[j]) continue;
			dp[i][j] = (dp[i][j] + dp[i + 1][j + 1]) % mod;
		}
	}
	printf("%lld\n", dp[0][0]);

	return 0;
}