#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,j,n) for(int i=(j);i<(n);i++)
#define repe(i,j,n) for(int i=(j);i<=(n);i++)
#define repr(i,j,n) for(int i=(n)-1;i>=0;i--)

int mod=1e9+7;


signed main(){
	int n,m;cin>>n>>m;
	vector<int> s(n),t(m);
	rep(i,n)cin>>s[i];
	rep(i,m)cin>>t[i];
	vector<vector<int>>dp(n+1,vector<int>(m+1,0));
	dp[0][0]=1;

	rep(i,n+1)rep(j,m+1){
		if(i>0)(dp[i][j]+=dp[i-1][j])%=mod;
		if(j>0)(dp[i][j]+=dp[i][j-1])%=mod;
		if(i>0&&j>0&&s[i-1]!=t[j-1])(dp[i][j]+=mod-dp[i-1][j-1])%=mod;
	}
	cout<<dp[n][m]<<endl;
}
