#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll ;
 
ll M=1000000007;
ll a[2003],b[2003];
ll s[2002][2002];
int main()
{
    ll m,n; cin>>m>>n;
    for (int i=1; i<=m; i++) cin>>a[i];
    for (int i=1; i<=n; i++) cin>>b[i];
    
    s[0][0]=1;
    for (int i=1; i<=m; i++) s[i][0]=1;
    for (int j=1; j<=n; j++) s[0][j]=1;
    
    for (int i=1; i<=m; i++)
        for (int j=1; j<=n; j++)
        {
        	ll ans;
        	ans=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
        	if (a[i]==b[j]) ans+=s[i-1][j-1];
        	ans%=M;
        	s[i][j]=ans;
		}
		
	if (s[m][n]<0) s[m][n]+=M;
	cout << s[m][n] << endl;
        
}