#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 2020;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =  1e9+7;
ll n,m;
ll a[N];
ll b[N];
ll dp[N][N];

int main()
{
cin>>n>>m;
rep(i,1,n+1)
cin>>a[i];
rep(i,1,n+1)
cin>>b[i];
rep(i,0,N)
{
	dp[i][0]=1;
	dp[0][i]=1;
}
rep(i,1,n+1)
{
	rep(j,1,m+1)
	{
		if(a[i]==b[j])
		{

		dp[i][j]=dp[i-1][j]+dp[i][j-1];

	}
		else
		dp[i][j]=(mod+dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]);
	
	   	dp[i][j]=(dp[i][j])%mod;
	}
}
cout<<dp[n][m];
}
	

