#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<tuple>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
const ll MOD = 1e9 + 7;
const int INF = 1e9 + 7;

#define DEBUG 1

ll dp[2055][2055];

int main() {

	
	ll n, m;
	cin >> n >> m;
	vector<int> s(n+10,0), t(m+10,0);
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> t[i];
	}

	dp[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (s[i] == t[j]) {
				dp[i + 1][j] += dp[i][j];
				dp[i][j + 1] += dp[i][j];

				dp[i + 1][j] %= MOD;
				dp[i][j + 1] %= MOD;
			}
			else
			{
				dp[i + 1][j] += dp[i][j];
				dp[i][j + 1] += dp[i][j];

				dp[i + 1][j] %= MOD;
				dp[i][j + 1] %= MOD;

				dp[i + 1][j + 1] -= dp[i][j];
				dp[i + 1][j + 1] %= MOD;
			}
		}
	}

	

	cout << dp[n][m]%MOD << endl;



	return 0;
}
