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

const int maxn = 2e3 + 6;
const int mod = 1e9 + 7;

int n, m, s[maxn], t[maxn], dp[maxn][maxn], ps[maxn][maxn];
int ans = 1;
int main() {
	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]) * (ps[i - 1][j - 1] + 1)) % mod;
			ps[i][j] = (ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + (s[i] == t[j]) * (ps[i - 1][j - 1] + 1)) % mod;
		}
	}
	ans += mod;
	cout << ans % mod;
}