#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll md=1e9+7;
ll dp[2010][2010];
ll su[2010][2010];
int s[2010],t[2010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	memset(dp,0,sizeof(dp));
	memset(su,0,sizeof(su));
	for(int i=1;i<=n;i++){
		scanf("%d",&s[i]);
	} 
	for(int i=1;i<=m;i++){
		scanf("%d",&t[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i]==t[j]){
				dp[i][j]=(su[i-1][j-1]+1)%md;
				su[i][j]=(su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j]+md)%md;
			}
			else{
				dp[i][j]=0;
				su[i][j]=(su[i-1][j]+su[i][j-1]-su[i-1][j-1]+md)%md;
			}
		}
	}
	printf("%lld\n",(su[n][m]+1)%md);
	return 0;
}
