#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=2e3+7;
int dp[N][N];
int a[N],b[N];
const ll mod=1e9+7;
int n,m;
ll solve(int i,int j){
	if(dp[i][j]!=-1) {
		return dp[i][j];
	}
	if(i==n+1||j==m+1) {
		return 0;
	}
	ll ans=0;
	if(a[i]==b[j]) {
		ans= 1+solve(i,j+1)+solve(i+1,j);
	}
	else {
		ans=solve(i,j+1)+solve(i+1,j)-solve(i+1,j+1);
	}
	ans+=mod;
	ans%=mod;
	return dp[i][j]=ans;
}
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	memset(dp,-1,sizeof dp);
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=m; i++) cin>>b[i];

	//ans%=mod;
	cout<<solve(1,1)+1<<endl;


	return 0;
}
