#include <iostream>

using namespace std;

typedef long long ll;
const ll p = 1e9 + 7;
ll n, m, a[2005], b[2005], ans, f[2005][2005];

int main()
{
	cin >> n >> m;
	for (ll i = 1; i <= n; i++) cin >> a[i];
	for (ll i = 1; i <= m; i++) cin >> b[i];
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= m; j++)
		{
			f[i][j] = (f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + p) % p;
			if (a[i] == b[j])
			{
				f[i][j] = (f[i][j] + f[i - 1][j - 1] + 1 + p) % p;
			} 
			//cout << i << " " << j << " " << f[i][j] << endl;
		}
	}
	cout << (f[n][m] + 1 + p) % p << endl;
	return 0;
} 