#include<bits/stdc++.h>
#define ll long 
#define pii pair<int,int>
#define F first
#define S second
#define MP make_pair
#define pss pair<string,string>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
using namespace std;
const int N=2e3+5;
const ll mod=1e9+7;
int n,m,x[N],y[N];
ll dp[N][N];


int main()
{
	cin>>n>>m;
	for(ll i=1;i<=n;i++)cin>>x[i];
	for(ll i=1;i<=m;i++)cin>>y[i];
	for(ll i=0;i<N;i++)dp[i][0]=dp[0][i]=1;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			dp[i][j]=((dp[i-1][j]+dp[i][j-1])%mod-dp[i-1][j-1]+mod)%mod;//继承 
			if(x[i]==y[j])
				dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}