#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll dp[2001][2001];
int n, m;
vector<ll> u, v;

ll recur(int p, int q) {
	if(p >= n or q >= m)
		return 0;

	ll &ret = dp[p][q]; 
	if(ret != -1)
		return ret;

	ret = 0;
	if(u[p] == v[q])
		ret = 1 + recur(p+1, q+1);
	ret = (ret + ((recur(p+1, q) + recur(p, q+1))%MOD - recur(p+1, q+1) + MOD)%MOD)%MOD;

	return ret;
}

int main() {
	cin >> n >> m;
	u.resize(n), v.resize(m);
	memset(dp, -1, sizeof dp);
	
	for(int i = 0; i < n; ++i)
		cin >> u[i];
	for(int i = 0; i < m; ++i)
		cin >> v[i];

	cout << (recur(0, 0)+1)%MOD << endl;
	return 0;
}

