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

int main() {
	vector<ll> S(2019);
	vector<ll> T(2019);
	ll N, M, ans;
	cin >> N >> M;
	for (int i = 1;i < N + 1;i++) {
		cin >> S[i];
	}
	for (int i = 1;i < M + 1;i++) {
		cin >> T[i];
	}
	vector<vector<ll>> X(2019, vector<ll>(2019, 0));

	for (int i = 1;i < N + 1;i++) {
		for (int j = 1;j < M + 1;j++) {
			X[i][j] = X[i - 1][j] + X[i][j - 1] - X[i - 1][j - 1];
			if (S[i] == T[j]) {
				X[i][j] += X[i - 1][j - 1] + 1;
			}
			X[i][j] += MOD;
			X[i][j] %= MOD;
		}
	}
	cout << X[N][M] + 1 << endl;
}