#include <bits/stdc++.h>

#define MOD 1000000007

using namespace std;

int main() {
	
	int n, m, x;
	cin >> n >> m;
	vector<int> a(1, 0), b(1, 0);
	for (int i = 0; i < n; i++) {
		cin >> x;
		a.push_back(x);
	}
	for (int i = 0; i < m; i++) {
		cin >> x;
		b.push_back(x);
	}
	vector<vector<int>> f(n + 1, vector<int>(m + 1, 0));
	for (int i = 0; i <= n; i++) {
		f[i][0] = 1;
	}
	for (int j = 0; j <= m; j++) {
		f[0][j] = 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]) % MOD;
		    if (a[i] != b[j]) {
		      f[i][j] = (f[i][j] + MOD - f[i - 1][j - 1]) % MOD;
		    }
		}
	}
	cout << f[n][m] << endl;
}