#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
ll a,b,c,d,ans,N,M,K,q[2007],w[2007],dp[2007][2007],co=1000000007;
int main(){
	scanf("%lld%lld",&N,&M);
	rep(i,1,N) scanf("%lld",&q[i]);
	rep(i,1,M) scanf("%lld",&w[i]);
	dp[0][0]=1;
	rep(i,1,N) dp[i][0]=1;
	rep(j,1,M) dp[0][j]=1;
	rep(i,1,N) rep(j,1,M) {
		dp[i][j]=((dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%co+co)%co;
		if (q[i]==w[j]) dp[i][j]=(dp[i][j]+dp[i-1][j-1])%co;
	}
	printf("%lld\n",dp[N][M]);
	return 0;
}
