#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+1),t(m+1);
	repe(i,n)cin>>s[i];
	repe(i,m)cin>>t[i];
	vector<vector<int>>num(n+1,vector<int>(m+1,0));
	vector<vector<int>>sum(n+1,vector<int>(m+1,0));
	num[0][0]=1;
	rep(i,n)sum[i][0]=1;
	rep(i,m)sum[0][i]=1;

	rep(i,n)rep(j,m){
		if(s[i]==t[j]){num[i+1][j+1]=sum[i][j];}
		sum[i+1][j+1]=(num[i+1][j+1]+sum[i+1][j]+sum[i][j+1]+mod-sum[i][j])%mod;
	}
	cout<<sum[n][m]<<endl;
}
