#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int a, b;
long long arra[99999], arrb[99999];
int main()
{
	cin >> a >> b;
	for(int i=1; i<=a; i++)
		cin >> arra[i];
	for(int i=1; i<=b; i++)
		cin >> arrb[i];
	long long dp[a + 100][b + 100] = {0};
	for(int i=1; i<=a; i++)
	{
		for(int j=1; j<=b; j++)
		{
			dp[i][j] = (long long)dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
			if(arra[i] == arrb[j])
				dp[i][j] += (long long)dp[i-1][j-1] + 1;
			dp[i][j] %= mod;
		}
	}
	printf("%lld\n",dp[a][b] + 1);
	return 0;
}