#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

ll dp[2020][2020];
int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll>S(N), T(M);
	rep(i, 0, N)cin >> S[i];
	rep(i, 0, M)cin >> T[i];

	dp[0][0] = 1;
	rep(i, 0, 2020)dp[i][0] = 1;
	rep(j, 0, 2020)dp[0][j] = 1;
	rep(i, 1, N+1)rep(j, 1, M+1) {
		if (S[i-1] == T[j-1]) {
			dp[i][j] += dp[i - 1][j - 1];
		}
		dp[i][j] += dp[i - 1][j] + dp[i][j-1];
		dp[i][j] -= dp[i - 1][j - 1];
		dp[i][j] %= MOD;
	}
	cout << dp[N][M] % MOD; << endl;

	return 0;
}
