#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int S[2001];
int T[2001];
ll dp[2001][2001];
ll sum[2001][2001];
int main() {
	int N, M;
	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++) {
			if (S[i] == T[j]) dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
			sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] + MOD - sum[i - 1][j - 1] + dp[i][j]) % MOD;
		}
	}
	ll ans = (sum[N][M] + 1) % MOD;
	cout << ans << endl;
}