#include <bits/stdc++.h>
#define ll long long
#define Mod 1000000007
#define N 2004

using namespace std;

int n, m;
ll f[N][N];
int s[N], t[N];

int main(){
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		scanf("%d", s + i),f[i][0] = 1;
	for (int i = 1; i <= m; ++i)
		scanf("%d", t + i),f[0][i] = 1;
	f[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			(f[i][j] += (f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1]) % Mod) %= Mod;
			if (s[i] == t[j])
				(f[i][j] += f[i - 1][j - 1]) %= Mod;
		}
	}

	cout << (f[n][m] % Mod + Mod) % Mod << endl;
	return 0;
}

