#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	ll a[n + 1], b[m + 1], dp[n + 1][m + 1];
	vector <ll> cur(100001);
	
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= m; i++) cin >> b[i];
	
	for (int i = 0; i <= m; i++) dp[0][i] = 1;
	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = 1;
		cur.assign(100001, 0);
		for (int j = 1; j <= m; j++)
		{
			cur[b[j]] = (cur[b[j]] + dp[i - 1][j - 1]) % mod;
			dp[i][j] = (dp[i - 1][j] + cur[a[i]]) % mod;
		}
	}
	cout << dp[n][m];
}