#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll MOD = 1e9+7;

	ll N, M;
	cin >> N >> M;

	vector<ll> S(N);
	rep(i, N) cin >> S[i];

	vector<ll> T(M);
	rep(i, M) cin >> T[i];

	vector<vector<ll>> dp(N+1, vector<ll>(M+1, 0));
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			dp[i+1][j+1] += dp[i+1][j];
			dp[i+1][j+1] %= MOD;
			dp[i+1][j+1] += dp[i][j+1] - dp[i][j] + MOD;
			dp[i+1][j+1] %= MOD;
			if(S[i] == T[j]){
				dp[i+1][j+1] += dp[i][j] + 1;
				dp[i+1][j+1] %= MOD;
			}

		}
	}

	cout << dp[N][M] + 1 << endl;
}
