#include <iostream>
using namespace std;

const int MAXN = 2e3 + 10, MOD = 1e9 + 7;
int s[MAXN], t[MAXN], n, m;
long long dp[MAXN][MAXN];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> s[i], dp[i + 1][0] = 1;
	for (int j = 0; j < m; j++)
		cin >> t[j], dp[0][j + 1] = 1;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
			if (s[i - 1] == t[j - 1])
				dp[i][j] += dp[i - 1][j - 1];
			dp[i][j] %= MOD;
		}
	if (dp[n][m] < 0)
		dp[n][m] += MOD;
	cout << dp[n][m];
}