#include <iostream>

using namespace std;

long long dp0[2005][2005];
long long dp1[2005][2005];

int main(int argc, char *argv[])
{
	int N, M;
	int S[2005], T[2005];
	long long mod = 1000000007;

	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> T[i];
	}

	dp0[0][0] = 1;
	for (int i = 0; i < N + 1; i++) {
		for (int j = 0; j < M + 1; j++) {
			(dp0[i + 1][j] += dp0[i][j] % mod) %= mod;
			(dp1[i][j] += dp0[i][j] % mod) %= mod;
			(dp1[i][j + 1] += dp1[i][j] % mod) %= mod;
			if (S[i] == T[j]) {
				(dp0[i + 1][j + 1] += dp1[i][j] % mod) %= mod;
			}
		}
	}
	cout << dp1[N][M] << endl;

	return 0;
}