#include <iostream>
#include <map>
using namespace std;
long long dp[2010][2010],mod = 1000000007;
int s[2010],t[2010];
map<int,long long> mp;
int main(){
	int i,j,n,m;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> s[i];
	}
	for(i=0;i<m;i++){
		cin >> t[i];
	}
	for(i=0;i<=n;i++){
		dp[i][0] = 1;
	}
	for(i=0;i<=m;i++){
		dp[0][i] = 1;
	}
	for(i=0;i<n;i++){
		mp.clear();
		for(j=0;j<m;j++){
			(mp[t[j]] += dp[i][j]) %= mod;
			dp[i+1][j+1] = (dp[i][j+1] + mp[s[i]])%mod;
		}
	}
	cout << dp[n][m] << endl;
}
	