#include<iostream>
#include<algorithm>
using namespace std;
int s[2005], t[2005];
long long f[2005][2005];
long long mod = 1e9 + 7;
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> s[i];
	for (int i = 1; i <= m; i++)
		cin >> t[i];
	for (int i = 0; i <= n; i++)f[i][0] = 1;
	for (int i = 0; i <= m; i++)f[0][i] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			f[i][j] = (f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + mod) % mod;
			//f[i][j]记录的是1~i,1~j各项f[i][j]的和
			if (s[i] == t[j])
				f[i][j] = (f[i][j] + f[i - 1][j - 1]) % mod;	//相当于各项都了延长1
		}
	cout << f[n][m] << endl;
	return 0;
}