#include <bits/stdc++.h>
using namespace std;
 
#define int long long

const int N = 2e3 + 10, mod = 1e9 + 7;
int n, m, ans = 1, s[N], t[N], psum[N][N];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	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 = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			ans = (ans + (s[i] == t[j]) * (psum[i - 1][j - 1] + 1)) % mod;
			psum[i][j] = (psum[i][j - 1] + psum[i - 1][j] - psum[i - 1][j - 1] + (s[i] == t[j]) * (psum[i - 1][j - 1] + 1)) % mod;
		}
	cout << (ans + mod) % mod << endl;
}