#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
int n,m;
long long s[3010],t[3010],dp[3010][3010];
signed main(){
	cin>>n>>m;
	rep(i,n)cin>>s[i];
	rep(i,m)cin>>t[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1]){
				dp[i][j]=1+dp[i][j-1]+dp[i-1][j];
			}
			else{
				dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
			}
			dp[i][j]=(dp[i][j]+MOD)%MOD;
		}
	}
	cout<<(dp[n][m]+1)%MOD<<endl;
	return 0;
}
